-
Notifications
You must be signed in to change notification settings - Fork 529
Add Type::searchArray()
#1874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Type::searchArray()
#1874
Conversation
The null behaviour should be kept - if we're aware of these regressions we should fix them :) Actually it should be |
yeah, adding the php-version check makes sense. regarding |
The ErrorType doesn't do anything useful, it's basically a MixedType. There's additional downside to ErrorType with arrays - because of some logic in NodeScopeResolver, if you add a new offset to ErrorType, a new array shape (ConstantArrayType) is created, leading to most likely wrong analysis... NeverType at least signals that no code after this point is executed because it crashes/throws an exception. |
I wonder if it makes sense to keep the error types in the traits/types and let only the extensions return null/never depending on php version in case is array()->no(). It still feels inconsistent, but maybe I just need to play around with it.. |
well, I think this is looking better, but it feels more correct to let the NonArrayTypeTrait return NEVER too, but that would cancel it out in a union I guess. on the other hand I'm not sure if ERROR is the right type there either, see e.g LegacyNodeScopeResolverTest diff. also: I can't check for the PHP version in types, can I? 🤔 |
This pull request has been marked as ready for review. |
Another idea: the nonarray trait could return a nulltype, which is what the array functions would do without enforcing the array arg type. The extension checks php version and isArray() and either returns nulltype/nevertype directly, does something different with maybe or passes the type through for a yes(). That could improve the type over all php versions. Not sure yet what should happen with e.g. array|false on php 8+ though. Maybe errortype |
I wouldn't pass PHP array functions weirdnesses into the Type system layer. Most likely it would lead to weird results in union/intersection types, and also it'd be misinformative for other uses... |
What do you think of the current state then or any other ideas? I'm not a 100% happy with it, unsure about unions mostly. But in order to keep the type for pre php 8 I'd need to modify the maybearraytypetrait somehow I guess. Which would mess with the type on php 8+. Except we change that and handle it maybe differently in the extension |
Nevermind, I think I know how to improve it in the extension with a bit of extra code for old php. That shouldn't mess with the type system either. I'll try later :) |
I give up, my super smart plan was to handle the |
This pull request has been marked as ready for review. |
Really nice, thank you 😊 |
Split out of the extension, but with a couple of small differences
null
(happened on PHP < 8 with a warning, see https://3v4l.org/lNrqs) it returns*ERROR*
. not sure if that's OK?HasOffsetValueType
which wasn't understood before, see https://phpstan.org/r/e20727f4-7809-42fc-825e-85df0f5ef635not sure if
$strictType
should be moved into the method signature as well or not 🤔