Incomplete parameter type for index options #6732

Open
opened 2026-01-22 15:37:40 +01:00 by admin · 0 comments
Owner

Originally created by @mbabker on GitHub (May 24, 2021).

With ORM 2.9, PHPStan gives a Parameter $options of attribute class Doctrine\ORM\Mapping\Index constructor expects array<string>|null, array<string, array<int, string>> given. error when configuring an index using PHP 8 attributes and specifying an index length in the options array, it looks like the options are typehinted to a single level associative array.

<?php declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table]
#[ORM\Index(columns: ['name'], name: 'thing_name_idx', options: ['lengths' => ['100']])]
class Thing
{
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    private ?int $id = null;

    #[ORM\Column(type: 'string', length: 400)]
    public string $name = '';
}

Not setting the lengths option as an array produces a array_filter(): Argument #1 ($array) must be of type array, string given TypeError in Doctrine\DBAL\Schema\Index::hasSameColumnLengths().

Originally created by @mbabker on GitHub (May 24, 2021). With ORM 2.9, PHPStan gives a `Parameter $options of attribute class Doctrine\ORM\Mapping\Index constructor expects array<string>|null, array<string, array<int, string>> given.` error when configuring an index using PHP 8 attributes and specifying an index length in the options array, it looks like the options are typehinted to a single level associative array. ```php <?php declare(strict_types=1); namespace App\Entity; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] #[ORM\Table] #[ORM\Index(columns: ['name'], name: 'thing_name_idx', options: ['lengths' => ['100']])] class Thing { #[ORM\Column(type: 'integer')] #[ORM\Id] #[ORM\GeneratedValue(strategy: 'AUTO')] private ?int $id = null; #[ORM\Column(type: 'string', length: 400)] public string $name = ''; } ``` Not setting the `lengths` option as an array produces a `array_filter(): Argument #1 ($array) must be of type array, string given` TypeError in `Doctrine\DBAL\Schema\Index::hasSameColumnLengths()`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6732