php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65218 Reference class constant from object property
Submitted: 2013-07-07 22:57 UTC Modified: 2013-07-21 17:28 UTC
From: mail at thomasbachem dot com Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: 5.4.17 OS: Mac OS X 10.8
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mail at thomasbachem dot com
New email:
PHP Version: OS:

 

 [2013-07-07 22:57 UTC] 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 ';'"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-21 17:28 UTC] arpad@php.net
-Status: Open +Status: Wont fix
 [2013-07-21 17:28 UTC] arpad@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 16:01:29 2024 UTC