rfc:uniform_variable_syntax
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:uniform_variable_syntax [2014/06/06 16:03] – nikic | rfc:uniform_variable_syntax [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
* Date: 2014-05-31 | * Date: 2014-05-31 | ||
* Author: Nikita Popov < | * Author: Nikita Popov < | ||
- | * Status: | + | * Status: |
- | * Proposed for: PHP 6 | + | * Discussion: http:// |
===== Introduction ===== | ===== Introduction ===== | ||
Line 52: | Line 52: | ||
// old meaning | // old meaning | ||
$$foo[' | $$foo[' | ||
- | Foo::$bar[' | + | $foo->$bar[' |
$foo-> | $foo-> | ||
+ | Foo:: | ||
</ | </ | ||
Line 76: | Line 77: | ||
Normally variable accesses are interpreted from left to right. '' | Normally variable accesses are interpreted from left to right. '' | ||
- | named '' | + | named '' |
The '' | The '' | ||
- | its '' | + | its '' |
with the name of the result. | with the name of the result. | ||
- | This combination of an indirect reference and an offset is the **only** case where interpretation is inverted. For | + | This combination of an indirect reference and an offset is the **only** case where the interpretation is inverted. For |
example the very similar '' | example the very similar '' | ||
It follows normal left-to-right semantics. Similarly '' | It follows normal left-to-right semantics. Similarly '' | ||
Line 92: | Line 93: | ||
'' | '' | ||
the 1, 2 and 3 offsets. On the other hand '' | the 1, 2 and 3 offsets. On the other hand '' | ||
- | entirely different interpretation. This does not call the function stored at '' | + | entirely different interpretation: This does not call the function stored at '' |
calls the static method of class '' | calls the static method of class '' | ||
The last issue implies that PHP's variable syntax is non-local. It is not possible to parse a PHP variable access with | The last issue implies that PHP's variable syntax is non-local. It is not possible to parse a PHP variable access with | ||
- | a fixed finite lookahead | + | a fixed finite lookahead, without transplanting the generated syntax tree or instructions after the fact. |
- | or instructions after the fact. | + | |
==== Impact on parser definition ==== | ==== Impact on parser definition ==== | ||
- | In addition to the problems described above the semantics for indirect references also has far-reaching consequences on | + | In addition to the problems described above the semantics for indirect references also have far-reaching consequences on |
- | how the variable syntax is defined in our parser. In the following I will outline the kind of issue it causes, for | + | how the variable syntax is defined in our parser. In the following I will outline the kind of issues |
readers not familiar with parser construction: | readers not familiar with parser construction: | ||
Line 158: | Line 158: | ||
Because of the implementational hurdles described in the previous section, we do not support all combinations of | Because of the implementational hurdles described in the previous section, we do not support all combinations of | ||
- | dereferencing operations to an arbitrary | + | dereferencing operations to an arbitrary |
'' | '' | ||
Line 166: | Line 166: | ||
syntax implemented in PHP 5.5 allows you to write '' | syntax implemented in PHP 5.5 allows you to write '' | ||
possible. Yet another example is that the alternative array syntax '' | possible. Yet another example is that the alternative array syntax '' | ||
- | i.e. '' | + | i.e. '' |
The second class of issues is that some nesting types aren't supported altogether. For example '' | The second class of issues is that some nesting types aren't supported altogether. For example '' | ||
Line 182: | Line 182: | ||
==== Miscellaneous other issues ==== | ==== Miscellaneous other issues ==== | ||
- | === Behavior in write/ | + | === Behavior in non-read |
The new '' | The new '' | ||
- | " | + | " |
- | if it would be technically possible. E.g. there is nothing inherently problematic with writing | + | |
- | '' | + | |
- | this is not allowed. | + | |
- | Furthermore this causes inconsistent behavior in '' | + | For example |
- | will generate an " | + | |
+ | This also means that assignments to dereferences of parenthesis-expressions are never allowed, even when they would be technically possible. E.g. it's not possible to write '' | ||
=== Superfluous CVs on static property access === | === Superfluous CVs on static property access === | ||
Line 198: | Line 196: | ||
'' | '' | ||
needs to be implemented to support our weird indirect reference semantics. | needs to be implemented to support our weird indirect reference semantics. | ||
- | |||
- | === TODO === | ||
===== Proposal ===== | ===== Proposal ===== | ||
Line 274: | Line 270: | ||
< | < | ||
- | $$foo[' | + | $$foo[' |
- | Foo::$bar[' | + | $foo->$bar[' |
- | $foo-> | + | $foo-> |
+ | Foo:: | ||
</ | </ | ||
- | This change is **backwards incompatible** (with low practical impact), which is the reason why this RFC targets PHP 6. | + | This change is **backwards incompatible** (with low practical impact), which is the reason why this RFC targets PHP 7. |
However it is always possible to recreate the old behavior by explicitly using braces: | However it is always possible to recreate the old behavior by explicitly using braces: | ||
- | < | + | < |
${$foo[' | ${$foo[' | ||
Foo:: | Foo:: | ||
Line 288: | Line 285: | ||
</ | </ | ||
- | This syntax will have guaranteed same behavior in both PHP 5 and PHP 6. | + | This syntax will have guaranteed same behavior in both PHP 5 and PHP 7. |
==== Newly added and generalized syntax ==== | ==== Newly added and generalized syntax ==== | ||
Line 323: | Line 320: | ||
==== Class name variable for new expression ==== | ==== Class name variable for new expression ==== | ||
- | It has always been possible to create classes using a dynamic | + | It has always been possible to create classes using a dynamically specified |
However the supported variables are more limited in this case: They may not include calls anywhere, as this would cause | However the supported variables are more limited in this case: They may not include calls anywhere, as this would cause | ||
ambiguity with the constructor parameter list. New variables are now defined as follows: | ambiguity with the constructor parameter list. New variables are now defined as follows: | ||
Line 347: | Line 344: | ||
breaks. | breaks. | ||
- | The former is a change in the behavior of currently existing syntax: | + | The former is a change in the behavior of currently existing syntax. Examples: |
- | nowbe interpreted as '' | + | |
+ | <code php> | ||
+ | // old meaning | ||
+ | $$foo['bar'][' | ||
+ | $foo-> | ||
+ | $foo-> | ||
+ | Foo::$bar['baz']() Foo::{$bar[' | ||
+ | </ | ||
An analysis of the Zend Framework and Symfony projects (including standard dependencies) showed that only a single | An analysis of the Zend Framework and Symfony projects (including standard dependencies) showed that only a single | ||
occurrence of '' | occurrence of '' | ||
This occurrence must be replaced with '' | This occurrence must be replaced with '' | ||
- | PHP 5 and PHP 6. | + | PHP 5 and PHP 7. |
The latter change turns currently valid syntax into a parse error. Expressions like '' | The latter change turns currently valid syntax into a parse error. Expressions like '' | ||
longer valid and '' | longer valid and '' | ||
- | As these changes only apply to some very rarely used syntax, the breakage seems acceptable for PHP 6. | + | As these changes only apply to some very rarely used syntax, the breakage seems acceptable for PHP 7. |
===== Open issues ===== | ===== Open issues ===== | ||
The current patch introduces a new "write context" | The current patch introduces a new "write context" | ||
- | was as '' | + | was as '' |
not exist, whereas the latter does not throw a notice. | not exist, whereas the latter does not throw a notice. | ||
Line 380: | Line 384: | ||
The main changes are limited to the language parser and compiler. Furthermore some opcode handlers had to be modified | The main changes are limited to the language parser and compiler. Furthermore some opcode handlers had to be modified | ||
to support '' | to support '' | ||
+ | |||
+ | ===== Vote ===== | ||
+ | |||
+ | As this is a language change, a 2/3 majority is required for acceptance. The vote started on 2014-07-07 and ended on 2014-07-14. | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ |
rfc/uniform_variable_syntax.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1