I have a property that stores a class name as a string. I then want to use this to call a static method of said class. As far as I know, this is possible since PHP 5.3. I am running 5.6.x on a vagrant box.
I want to do this:
$item = $this->className::getItem($id);
But I get the following error:
Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)...
The following works fine:
$c = $this->className;
$item = $c::getItem($id);
Any idea why? Is this not the same thing?
classis a reserved (key)word in OOP, far as I remember. php.net/manual/en/reserved.keywords.php$this->class::getItem($id);is not clear. What is it{$this->class}::getItem($id);or$this->{class::getItem($id)};Who can tell?classwas reserved and updated my code to use a non-reserved word. I still had the issue so I left the post alone. I have edited it now to clear up that I am no longer using the reserved word.