Tim Schmidt
Tim Schmidt

Reputation: 684

PHP reference Class from variable with static method access

Gives an Error:

$this->model::byUserPermission()

Leads to: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)

Works:

$facade = $this->model;
$facade::byUserPermission()

Is this a PHP Bug? Or can someone explain this to my, why that is happening (I am using php 5.6 and i am new to php. From my point of view, both are exactly the same). Thanks

Upvotes: 6

Views: 52

Answers (1)

Schleis
Schleis

Reputation: 43700

The problem is that this statement $this->model::byUserPermission() is ambiguous. And can be interpreted in multiple ways.

1) You could be trying to use the model property of the class that you are in to call a class's static method. As you are attempting in your question.

2) You could also mean you want to access the property of the class returned by the static function byUserPermission() in the model class.

Upvotes: 2

Related Questions