-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Syntax tweaks #5061
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
Syntax tweaks #5061
Conversation
One thing I'm unsure about here is the instanceof syntax. It could also conceivably be Ideally we'd allow |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This allows operations that were previously allowed on constant strings on interpolated strings as well.
…g` sniff > Non-interpolated strings `"foo"` are currently considered fully dereferencable, i.e. constructions such as `"foo"[0]` or `"foo"->bar()` are considered legal (syntactically at least). However, interpolated strings `"foo$bar"` are non-dereferencable. > > This RFC proposed to treat both types of strings consistently, i.e. `"foo$bar"[0]`, `"foo$bar"->baz()` etc become legal. Ref: * https://wiki.php.net/rfc/variable_syntax_tweaks#interpolated_and_non-interpolated_strings * php/php-src#5061 * php/php-src@24e365f Includes unit tests. Relates to PHPCompatibility#809
…g` sniff > Non-interpolated strings `"foo"` are currently considered fully dereferencable, i.e. constructions such as `"foo"[0]` or `"foo"->bar()` are considered legal (syntactically at least). However, interpolated strings `"foo$bar"` are non-dereferencable. > > This RFC proposed to treat both types of strings consistently, i.e. `"foo$bar"[0]`, `"foo$bar"->baz()` etc become legal. Ref: * https://wiki.php.net/rfc/variable_syntax_tweaks#interpolated_and_non-interpolated_strings * php/php-src#5061 * php/php-src@24e365f Includes unit tests. Relates to PHPCompatibility#809
…g` sniff > Non-interpolated strings `"foo"` are currently considered fully dereferencable, i.e. constructions such as `"foo"[0]` or `"foo"->bar()` are considered legal (syntactically at least). However, interpolated strings `"foo$bar"` are non-dereferencable. > > This RFC proposed to treat both types of strings consistently, i.e. `"foo$bar"[0]`, `"foo$bar"->baz()` etc become legal. Ref: * https://wiki.php.net/rfc/variable_syntax_tweaks#interpolated_and_non-interpolated_strings * php/php-src#5061 * php/php-src@24e365f Includes unit tests. Relates to PHPCompatibility#809
…g` sniff > Non-interpolated strings `"foo"` are currently considered fully dereferencable, i.e. constructions such as `"foo"[0]` or `"foo"->bar()` are considered legal (syntactically at least). However, interpolated strings `"foo$bar"` are non-dereferencable. > > This RFC proposed to treat both types of strings consistently, i.e. `"foo$bar"[0]`, `"foo$bar"->baz()` etc become legal. Ref: * https://wiki.php.net/rfc/variable_syntax_tweaks#interpolated_and_non-interpolated_strings * php/php-src#5061 * php/php-src@24e365f Includes unit tests. Relates to PHPCompatibility#809
…g` sniff > Non-interpolated strings `"foo"` are currently considered fully dereferencable, i.e. constructions such as `"foo"[0]` or `"foo"->bar()` are considered legal (syntactically at least). However, interpolated strings `"foo$bar"` are non-dereferencable. > > This RFC proposed to treat both types of strings consistently, i.e. `"foo$bar"[0]`, `"foo$bar"->baz()` etc become legal. Ref: * https://wiki.php.net/rfc/variable_syntax_tweaks#interpolated_and_non-interpolated_strings * php/php-src#5061 * php/php-src@24e365f Includes unit tests. Relates to PHPCompatibility#809
…rencing > ... class constant accesses are only array and object dereferencable. This > means that while `Foo::$bar::$baz` is legal, `Foo::BAR::$baz` is not. > > This RFC proposes to make class constant accesses static derefencable as > well, so that `Foo::BAR::$baz` and `Foo::BAR::BAZ` become legal. Ref: * https://wiki.php.net/rfc/variable_syntax_tweaks#class_constant_dereferencability * php/php-src#5061 * php/php-src@ab154b7 Includes unit tests. Relates to PHPCompatibility#809.
…rencing (#1262) > ... class constant accesses are only array and object dereferencable. This > means that while `Foo::$bar::$baz` is legal, `Foo::BAR::$baz` is not. > > This RFC proposes to make class constant accesses static derefencable as > well, so that `Foo::BAR::$baz` and `Foo::BAR::BAZ` become legal. Ref: * https://wiki.php.net/rfc/variable_syntax_tweaks#class_constant_dereferencability * php/php-src#5061 * php/php-src@ab154b7 Includes unit tests. Relates to #809. Co-authored-by: Matt Turland <[email protected]>
RFC: https://wiki.php.net/rfc/variable_syntax_tweaks
This is a collection of minor syntactic extensions that cover holes left by the original uniform variable syntax RFC:
"foo$bar"
is now treated the same ways as"foobar"
, e.g. you can write"foo$bar"[0]
.__FUNCTION__[0]
becomes legal.Foo::CLASS_NAME::$bar
becomes legal.new (expr)
is now accepted. Previously it was not possible to use arbitrary expressions withnew
.$var instanceof (expr)
is now accepted.These are all edge cases, but things I've received complaints about over the years.