Req #65218 [Opn->Wfx]: Reference class constant from object property

From: Date: Sun, 21 Jul 2013 17:28:24 +0000
Subject: Req #65218 [Opn->Wfx]: Reference class constant from object property
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-180392@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65218&edit=1 ID: 65218 Updated by: arpad@php.net Reported by: mail at thomasbachem dot com Summary: Reference class constant from object property -Status: Open +Status: Wont fix Type: Feature/Change Request Package: Class/Object related Operating System: Mac OS X 10.8 PHP Version: 5.4.17 Block user comment: N Private report: N New Comment: It's completely unclear whether "$anotherObj->myObj::MY_CONST" should refer to the property named by myObj::MY_CONST or the constant of the class named by $anotherObj->myObj. Previous Comments: ------------------------------------------------------------------------ [2013-07-07 22:57:29] mail at thomasbachem dot com Description: ------------ When referencing a class constant, as of PHP 5.3.0, it's possible to reference the class using a variable, e.g. "$myObj::MY_CONST". It's not possible however to use that syntax with object properties, e.g. "$anotherObj->myObj::MY_CONST". I think that's inconsistent. Test script: --------------- <?php class MyClass { const MY_CONST = 'foo'; } $myObj = new MyClass(); // Works, prints "foo" // echo $myObj::MY_CONST; $anotherObj = new stdObject(); $anotherObj->myObj = $myObj; // Raises a parse error echo $anotherObj->myObj::MY_CONST; Expected result: ---------------- Prints "foo" Actual result: -------------- Raises "Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting ',' or ';'" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65218&edit=1

« previous php.bugs (#180392) next »