$class_name::$const_name syntax
| From: | Antony Dovgal | Date: | Wed, 21 Apr 2004 10:53:58 +0000 |
| Subject: | $class_name::$const_name syntax | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-9456@lists.php.net to get a copy of this message | ||
Hi all!
I know, it's too late to propose such things before PHP5.0.0, but maybe there is a chance to
include it to 5.1...
Short example:
<?
class Some {
const singleton = true;
}
$class_name = "Some";
/* I'd like to have such syntax */
if ($class_name::singleton) { //doesn't work ATM
/* blah-blah */
}
if (eval("$class_name::singleton") { //DOES work ATM, but is really ugly
/* blah-blah */
}
$class_name = "Some";
$const_name = "singleton";
/* AND/OR even such syntax */
if ($class_name::$const_name) { //doesn't work ATM
/* blah-blah */
}
?>
I found similar ideas here: http://lists.php.net/article.php?group=php.internals&article=7980,
but this patch doesn't allow to fetch constants from the class.
I've tried to write a patch for language parser, but I found this bison/yacc stuff too tricky
for me =(
IMHO this addon will not affect other stuff (at least I can't see any possible problems it
could cause), but could be very useful.
Is it possible to implement such syntax in 5.x ?
---
WBR,
Antony Dovgal aka tony2001
tony2001@phpclub.net || antony@dovgal.com