简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM