PHP引用類來自具有靜態方法訪問的變量

[英]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

這是PHP Bug嗎?或者有人能給我解釋一下為什么會這樣嗎?在我看來,兩者完全相同)。謝謝

1 个解决方案

#1


2  

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

問題是這個語句$this->模型::byUserPermission()是不明確的。可以有多種解釋。

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.

1)可以嘗試使用所在類的model屬性來調用類的靜態方法。就像你在回答你的問題一樣。

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

您還可以表示您想要訪問模型類中的靜態函數byUserPermission()返回的類的屬性。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/09/23/72067ca4df93af0ada501fb33acea0f0.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com