vscode-intelephense
vscode-intelephense copied to clipboard
Understand extended phpdoc types like `list`
Feature description or problem with existing feature I've got a list, but it expected an array. Every list is always an array, but intelephense thinks list is something separate from array.
Describe the solution you'd like Teach intelephense that every list is an array, but not every array is a list.
Additional context
/** @var list<array{id:string}>*/
$test = $conn->select($query);
$test2 = array_map(static fn($x) => hydrateRow($x), $test);
// ^^^^^^
intelephense(1006) expected type array found list
I just updated to the latest version of Doctrine DBAL, which uses list
extensively for return types. The result is that my code is now littered with Expected type 'array'. Found 'Doctrine\DBAL\list<array<string, mixed>>'
errors wherever it takes the rows returned from a database query and treats them as an array e.g. by passing them to array_map
.
Looking at the Psalm documentation for list
, it does seem safe to treat lists as arrays in Intelephense, and Doctrine is sufficiently widely used that it would save a lot of grief.
Any workaround for this until it becomes supported?
+1 for this - as list<Type>
gets more and more widely used now (and is supported by PHPStorm for example).
Yes, please. list<Type> is widely used now. Especially in Doctrine.
Thank you for your great tool!
Please add my name to this list of those that would love to have support for this added!
Expected type 'Countable|array'. Found 'Doctrine\DBAL\list<array<string, mixed>>
Just wanted to say thanks for fixing this - my code looks a whole lot less red now.
@bmewburn The Intelephense is still best tool for PHP in VSCODE. Thank you, my savior! Please keep going. I you feel disappointed , don't be confused to ask money for new major version. Although I am homeless coder from ex Russia, but want to be thankful somehow. So if you have a donation page I did notice, pls let me know.