In another one of my tests, I noticed that in PHP there is a problem when trying to access the static method of a class, when that class is instantiated in a property of another class;
More specifically, I'm having problem with ::
- Scope resolution operator.
This is the Example class:
class Stack
{
public $overflow;
public static function overflow()
{
return 'overflow';
}
}
In the case below, I can access the static method through T_PAAMAYIM_NEKUDOTAYIM
normally.
$stack = new Stack;
$stack::overflow();
However, in the case below, I can no longer do this:
$object = new stdClass;
$object->stack = $stack = new Stack;
$object->stack::overflow();
Because it generates the error:
Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)
I would not like to do something like the examples below:
$object = new stdClass;
$object->stack = $stack = new Stack;
// Copia para aceitar a sintaxe
$stack = $object->stack;
$stack::overflow();
// usa uma função para chamar o método estático
forward_static_call($object->stack, 'overflow');
Is there any simpler way to do this in PHP (without having to resort to methods or copies of variables)?