com php-langspec: Fix semantics of variable parsing: spec/10-expressions.md
[email protected] (Stanislav Malyshev) Fri, 01 Jan 2016 22:54:16 +0000
| Newsgroups | php.standards.cvs |
|---|---|
| Message-ID | <[email protected]> |
Commit: e7a6118b500f7615ee6a49b1ff891694ffc5e9a7 Author: Stanislav Malyshev <[email protected]> Fri, 1 Jan 2016 14:54:16 -0800 Parents: 634b09d988c2f3716e50b2738fa5f202b724ba79 Branches: master Link: http://git.php.net/?p=php-langspec.git;a=commitdiff;h=e7a6118b500f7615ee6a49b1ff891694ffc5e9a7 Log: Fix semantics of variable parsing Changed paths: M spec/10-expressions.md Diff: diff --git a/spec/10-expressions.md b/spec/10-expressions.md index c7d3c70..62a2e43 100644 --- a/spec/10-expressions.md +++ b/spec/10-expressions.md @@ -1904,10 +1904,9 @@ might not be permitted as a [variable-name](09-lexical-structure.md#names) sourc The operator will consume the following *variable-name-creation-expression* and *variable-name* tokens, and also tokens representing [subscript operator](#subscript-operator). -I.e., in example `$$o->pr` the expression is treated as `${$o}->pr`, i.e. it is parsed as -"take the value of $o, consider it a variable name, and assuming the variable with this name -is an object take the property 'pr' of it". -However, in the expression ``$$a[0]` the tokens `$a[0]` would be treated as the variable name, not just `$a`. +In the absense of braces, the variable is parsed with left-to-right semantics, i.e., in example `$$o->pr` +the expression is treated as `${$o}->pr`, i.e. it is parsed as "take the value of $o, consider it a variable name, +and assuming the variable with this name is an object take the property 'pr' of it". **Examples** @@ -1929,9 +1928,9 @@ function f1 () { return 2.5; } ${1 + f1()} = 1000; // equivalent to ${3.5} = 1000 // ----------------------------------------- $v = array(10, 20); $a = 'v'; -$$a[0] = 5; // [] has higher precedence than $, $v is now 5 +$$a[0] = 5; // $v is [5, 20], since $$a is on the left of [] so it gets the first shot $v = array(10, 20); $a = 'v'; -${$a[0]} = 5; // equivalent to above, $v is 5 +${$a[0]} = 5; // $v is 5 $v = array(10, 20); $a = 'v'; ${$a}[0] = 5; // $ gets first shot at $a, $v is [5, 20] ```