Running PHP 5.4, so I wasn't expecting
this, but I'm encountering the following
error:
Parse error: syntax error,
unexpected '::'
(T_PAAMAYIM_NEKUDOTAYIM)
Assume
you have a variable of stdClass
setup as
follows:
$this->variable
= new stdClass();
$this->variable->other = array('class'
=>
'helloworld');
Now,
assume you want to access a static method of class
helloworld
:
//
Standard call
$x =
helloworld::my_static_method();
// Call with variable
class name
$x =
$this->variable->other['class']::my_static_method();
When
calling the above using the variable class name, I receive the parsing error. What's
odd, is that if I do the following, no error is
presented:
$class =
$this->variable->other['class'];
$x =
$class::my_static_method();
To
me this seems very odd, can anyone think of a reason why the class name isn't resolving
correctly when using the first example versus the second?
No comments:
Post a Comment