Req->Bug #72903 [Opn->Csd]: Spec does not allow $objInstance->memberObj::$staticVar syntax
[email protected] Thu, 28 Sep 2017 16:04:21 GMT
| Newsgroups | php.standards |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=72903&edit=1 ID: 72903 Updated by: [email protected] Reported by: dliebner at gmail dot com Summary: Spec does not allow $objInstance->memberObj::$staticVar syntax -Status: Open +Status: Closed -Type: Feature/Change Request +Type: Bug -Package: Scripting Engine problem +Package: PHP Language Specification PHP Version: 7.0 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: The spec @ https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#scope-resolution-operator now specifies the syntax correctly. Previous Comments: ------------------------------------------------------------------------ [2016-08-20 02:58:29] [email protected] PHP 5.6 does not support that syntax, and I don't think {}s can help with it. PHP 7 does. https://3v4l.org/ad03D Looking at the spec [1], I see two problems with "$obj->childClass::$var": 1. $obj->childClass would be classified as a scope-resolution-qualifer > expression, which "must be a value of type string [...] that contains the name of a class or interface type". This is not true: objects are supported, as seen in class Example { static $foo = "bar"; } $e = new Example(); echo $e::$foo; // bar 2. $var must be a member-selection-designator, however that is defined [2] as either a name (without a '$') or "a value of type string [...] that contains the name of an instance property (without the leading $) [or a method]". Neither of those cover the static property usage (which the prose for the scope-resolution operator calls "otherwise"), thus referencing member-selection-designator is insufficient; I think adding a ":: $ name" covers this case. So I'm repurposing this bug to deal with the spec. [1] https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#scope-resolution-operator [2] https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#member-selection-operator ------------------------------------------------------------------------ [2016-08-19 22:51:29] dliebner at gmail dot com Description: ------------ --- From manual page: http://www.php.net/language.oop5.static --- Code sample below yields 'unexpected T_PAAMAYIM_NEKUDOTAYIM' syntax error. Test script: --------------- <?php class MyClass { public static $var = 'yay!'; public $childClass; public function __construct() { $this->childClass = new ChildClass(); } } class ChildClass { public static $var = 'yay?'; } $obj = new MyClass(); echo $obj::$var; // works echo $obj->childClass::$var; // syntax error ?> Expected result: ---------------- yay!yay? Actual result: -------------- Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting ',' or ';' in __FILE__ on line 25 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72903&edit=1