Replies: 6 comments 7 replies
|
PHPStan doesn't support recursive types as they're very hard to do, but here's an idea - you could have the actual config structure here - specific keys, specific structures in those keys. It's a question of a dynamic return type extension (https://phpstan.org/developing-extensions/dynamic-return-type-extensions). Also look into array shapes: https://phpstan.org/writing-php-code/phpdoc-types#array-shapes |
|
Thanks in advance. i will have a look at the extensions. Thank you. On the other hand:
|
|
I think the simplest solution is adding Details Array access on offset of strict mixed (level 9) is happening, because currently I'm working around this, see phpstan/phpstan-src#1237 for details.
If this is solved, error except in line 26 would not be report. |
|
because of type normalizing, https://phpstan.org/developing-extensions/type-system#type-normalization PHPStan normalizes array<int|string, mixed>|mixed to mixed. I can say is_array is the only solution I can think for now… |
|
Ah... such a ... its not solved :( Still same problem. Changelog for 1.7.0 then seems wrong, or?:
Or what has changed? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
// phpstan 1.6.8 , php8.0
Hi
In short: how to fix that?:
https://phpstan.org/r/3da85197-12db-47c2-a158-a52f0f7c7f7a
In long:
a config comes from a config file which always will be an array.
E.g:
return require 'config.php'; // => array<int|string, mixed>the data to be used.
where
mixedis rather the short write forscalar|array|nulljust scalar|array|null exists in realwhich can be nested in N-depth (e.g. merging several configs)
a function can return array or mixed (scalar|array|null) but testing eg for a not mixed type
isset( $config[ $key ])phpstan does not undertand or i dont :-)where is the trick? or is it too generic?
Kind regards Florian
All reactions