Skip to content

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

Merged
merged 7 commits into from
Feb 11, 2020
Merged

Syntax tweaks #5061

merged 7 commits into from
Feb 11, 2020

Conversation

nikic
Copy link
Member

@nikic nikic commented Jan 6, 2020

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].
  • Magic constants are treated the same as normal constants, e.g. __FUNCTION__[0] becomes legal.
  • Class constants become fully dereferencable, in particular Foo::CLASS_NAME::$bar becomes legal.
  • new (expr) is now accepted. Previously it was not possible to use arbitrary expressions with new.
  • Similarly $var instanceof (expr) is now accepted.

These are all edge cases, but things I've received complaints about over the years.

@nikic nikic added the RFC label Jan 6, 2020
@nikic
Copy link
Member Author

nikic commented Jan 6, 2020

One thing I'm unsure about here is the instanceof syntax. It could also conceivably be $foo instanceof (expr).

Ideally we'd allow $foo instanceof expr, but that doesn't work because of the constant vs class name conflict. We could resolve it by parsing the RHS as a constant and then performing a class bit of fixup to convert a top-level constant access to a class name reference, but I'm afraid that doing this will cause problems in the future, once we add support for generics.

@Guojunzhou-git

This comment has been minimized.

@Guojunzhou-git

This comment has been minimized.

@Guojunzhou-git

This comment has been minimized.

@Guojunzhou-git

This comment has been minimized.

@Guojunzhou-git

This comment has been minimized.

@KalleZ

This comment has been minimized.

@php-pulls php-pulls merged commit c141ee3 into php:master Feb 11, 2020
thekid added a commit to xp-framework/compiler that referenced this pull request Feb 15, 2020
@carusogabriel carusogabriel added this to the PHP 8.0 milestone May 30, 2020
elazar pushed a commit to elazar/PHPCompatibility that referenced this pull request Nov 21, 2020
…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
elazar pushed a commit to elazar/PHPCompatibility that referenced this pull request Nov 21, 2020
…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
elazar pushed a commit to elazar/PHPCompatibility that referenced this pull request Nov 21, 2020
…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
elazar pushed a commit to elazar/PHPCompatibility that referenced this pull request Dec 2, 2020
…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
jrfnl pushed a commit to elazar/PHPCompatibility that referenced this pull request Dec 24, 2020
…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
elazar pushed a commit to elazar/PHPCompatibility that referenced this pull request Dec 27, 2020
…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.
jrfnl pushed a commit to PHPCompatibility/PHPCompatibility that referenced this pull request Dec 28, 2020
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants