-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Reflection does not detect optional parameter when they are in an invalid order and PHP does not see this as syntax error. #18127
Comments
Your example emits this warning:
This will become an error in PHP 9.0. That's what you're asking for, correct? |
@iluuu1994 Yes, that is correct. Good, that this will be an error in the future. |
No worries. Thanks for getting back to me. For completeness, the corresponding RFC:
Oops, wrong one. One sec. 🙂 |
I actually confused this proposal with another one. It looks like this change was made without an RFC: Which was discussed here: https://externals.io/message/108052 It's not completely clear from the discussion whether this should be promoted to an error in 9.0. I think it's best to send a follow-up e-mail and then actually add a TODO on the RFC page so that it is not forgotten. |
Description
I report this as bug, but it can also be an feature request.
What is the problem:
A class that defines a optional parameter before an non-optional parameter
Side Note:
My IDE PHP Storm normally shows an warning: Optional parameter is provided before required
But this only shows up, when both parameter don't have public
That was the reason why i noticed this hole issue.
Reflection does not detect the optional parameter when there are in the wrong order
As you can see in the provided code, the Reflection detects the parameter 'bar' in Foo as not optional.
Conclusion:
Maybe php should throw an syntax error when an wrong parameter order is detected.
Because this is invalid code, but is only detected at run-time under some special conditions.
That Reflection currently shows the result that is does, is maybe fully correct, but is also not so clear.
We are able to do new Foo(...['test'=>'bar']) and that is why i thing php must throw an error when wrong parameter order is detected in the first place.
The following code:
Resulted in this output:
But I expected this output instead:
PHP Version
PHP 8.4.5
Operating System
No response
The text was updated successfully, but these errors were encountered: