Best way to mix array<string, mixed>
with array shape
#5703
-
What would be the best way to mix an array with type For exemple, a database fetch associative with a given See full exemple here https://phpstan.org/r/731742b0-9915-4b73-842f-2e8ab7cf6800 A possibility is to manually typed the variable with some /** @var array{id: string, name: string} $row */
$row = $this->dbalFetchAssociative('SELECT id, name FROM users'); But I want to know if someone found a way to do it automatically or make the two types compatibles |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Another exemple where you cannot simply add https://phpstan.org/r/76c75577-786c-459e-b0af-4e2f6af2fa41 Using a useless variable just to add the type might be overkill :/ |
Beta Was this translation helpful? Give feedback.
-
If you can somehow deduce from |
Beta Was this translation helpful? Give feedback.
If you can somehow deduce from
'SELECT id, name FROM users'
how the array shape will look like, you can write a dynamic return type extension that will do it: https://phpstan.org/developing-extensions/dynamic-return-type-extensions