note 47804 added to language.oop5.constants
| From: | NormanClarke | Date: | Wed, 01 Dec 2004 01:06:57 +0000 |
| Subject: | note 47804 added to language.oop5.constants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81204@lists.php.net to get a copy of this message | ||
Perhaps I'm overlooking something, but in 5.0.2 it appears there's no way to access class
constants when the class name is a variable. Example:
class MyClass {
const A_CONSTANT = 62;
public $a_variable = 62;
}
$className = "MyClass";
$object = new $className;
// this will output "62."
echo $object->a_variable . "\n";
/*
* this will cause the dreaded "unexpected T_PAAMAYIM_NEKUDOTAYIM"
* parse error
*/
echo $object::A_CONSTANT;
----
Manual Page -- http://www.php.net/manual/en/language.oop5.constants.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47804
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47804&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47804&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47804&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47804&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47804&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47804&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47804&report=yes
Search -- http://master.php.net/manage/user-notes.php