Search code examples
phpindirection

PHP: limitation of variable variables


In php I can do this:

$class = 'Notes';
echo $class::message();

but it seems that from within a method, I can't do this:

echo ($this->myClass)::message(); 

and also cannot do this:

echo someFunctionThatReturnsClassName()::message();

Can anybody explain why? And give some rules about when and how this indirection mechanism works?

Thank you Gidi


Solution

  • This is not an issue with variable variables, it is an issue with PHP not allowing this syntax. There is a proposal for fixing this in the core, however this one has not been accepted yet: http://wiki.php.net/rfc/fcallfcall (and also http://wiki.php.net/rfc/functionarraydereferencing)