# $class_name::$const_name syntax

- Thread: https://externals.io/message/9456
- Original archive: https://news-web.php.net/php.internals/9456
- Started by Antony Dovgal on 2004-04-21T10:53:58+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #9456 — Antony Dovgal — 2004-04-21T10:53:58+00:00

URL: https://externals.io/message/9456#9456

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
