-
Notifications
You must be signed in to change notification settings - Fork 7.8k
null default-value parameter before required parameter is silently ignored #11485
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
Comments
This was old way to make nullable types, which was kept for compatibility, though I don't think it should be supported anymore. Originally PR #5067 included also this case, but it was changed as per this message. |
@KapitanOczywisty Thank you, very informative. I see how there's a bit of quirkiness due the desire to support "poor mans nullable type" for now then. Although it seems like this specific case was already discussed and only skipped because "it didn't seem worth it".
So yeah, there could be a deprecation for it, and I would argue there should be, but maybe it's too niche until "poor mans nullable type" is entirely deprecated. However, after reading more on that topic and further testing it appears I reduced the example too far. Our use-case is constructors with the promoted property syntax, which behaves differently it seems, and there it specifically seems like a bug due to the behavior of the other cases. I'll open a new issue instead to correctly detail the problem. |
This is really the same as #11488, see https://3v4l.org/G1oVv. #11497 should take care of this case. |
Description
The following code:
Resulted in this output:
But I expected this error instead:
To explain; $a does not end up being optional, and if you perform reflection on the property, it does not have a default-value. So PHP is silently ignoring the user-specified behavior. While it seems that PHP considers having optional properties in-front of required properties as invalid, it should at least issue a warning instead of silently changing expectations. If you put a string as default-value instead, it will emit the above depreciation notice.
PHP Version
PHP 8.2.7
Operating System
No response
The text was updated successfully, but these errors were encountered: