-
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
Allow using readonly as function name #7468
Conversation
Don't treat "readonly" as a keyword if followed by "(". This allows using it as a global function name. In particular, this function has been used by WordPress. This does not allow other uses of "readonly", in particular it cannot be used as a class name, unlike "enum". The reason is that we'd still have to recognize it as a keyword when using in a type position: class Test { public ReadOnly $foo; } This should now be interpreted as a readonly property, not as a read-write property with type `ReadOnly`. As such, a class with name `ReadOnly`, while unambiguous in most other circumstances, would not be usable as property or parameter type. For that reason, we do not support it at all.
@nikic I, for one, very much appreciate this PR. This will significantly lessen the risk of "white screens of death" for end-users of WordPress, so would be great if this PR gets accepted. |
This should target |
I'll discuss with the other 8.1 RMs. |
We can't declare global functions: public function try() {}
public function throw() {}
public function goto() {}
public function public() {}
public function protected() {}
public function private() {}
public function goto() {}
public function global() {}
public function var() {}
... While we actually could as none of those keywords are used with a following This would make the keyword This and being past RC1 doesn't make me super enthusiast about it.
|
Counter-point the I think allowing |
Ok, I regret the WP community haven't raised concerns while in alpha/beta, but I feel we haven't much choice and this is not the most critical thing in terms of decision. Unless I misunderstood something, we (RMs) are OK with this for PHP 8.1. (/cc @krakjoe / @ramsey) |
Could we allow |
As @patrickallaert said, this is approved to target PHP-8.1. |
I can't speak for WordPress, only for myself, however:
I fully support this being a temporary exception and for a deprecation warning to be added together with this change. Removing the exception in PHP 8.2 may be a bit soon. Would it be acceptable to remove it in PHP 9.0, similar to other deprecated functionality from the 8.x series? For context: Having said that, not all plugins/themes are still actively maintained, so having some more time will allow a) enough actively maintained plugins/themes to be fixed up and b) enough end-users to find alternative plugins/themes if the plugin/themes is no longer maintained.
As an active maintainer of various PHPCS based coding standards as well as contributor to PHPCS itself, I agree, yes, this will make it more difficult.
Actually I did raise this same concern before: #7089 (comment) |
Merged as 76348f3 Thanks. |
Thank you all for still making this change this late in the cycle 🙏🏻 💞 |
… names PHP 8.0 introduced `match` as a new reserved keyword and `mixed` as a new "other" reserved keyword. PHP 8.1 introduced `readonly` as a new reserved keyword, `never` as an "other" reserved keyword and `enum` as a soft reserved keyword. Note: `readonly` has an exception for when it is used as a function declaration name. Includes regenerated test case files. Refs: * https://wiki.php.net/rfc/match_expression_v2 * https://wiki.php.net/rfc/mixed_type_v2#backward_incompatible_changes * https://wiki.php.net/rfc/readonly_properties_v2 * https://wiki.php.net/rfc/enumerations * https://wiki.php.net/rfc/noreturn_type#backwards_incompatible_changes * php/php-src#7468 (readonly exception in PHP 8.1) * php/php-src#9512 (readonly exception PHP 8.2 follow-up)
Don't treat "readonly" as a keyword if followed by "(". This
allows using it as a global function name. In particular, this
function has been used by WordPress.
This does not allow other uses of "readonly", in particular it
cannot be used as a class name, unlike "enum". The reason is that
we'd still have to recognize it as a keyword when using in a type
position:
This should now be interpreted as a readonly property, not as a
read-write property with type
ReadOnly
. As such, a class withname
ReadOnly
, while unambiguous in most other circumstances,would not be usable as property or parameter type. For that
reason, we do not support it at all.
Based on the recent Twitter discussion, cc @jrfnl @ramsey @derickr. Unfortunately this is not such a clean case as
enum
, because we can only fully support the function case.