Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有
class Meat extends Food { $var = Food::foodFunction… }
我需要为 Food 类设置 $var,我该怎么做?
谢谢
如果$var在食品类中是一个protected/public变量,您只需使用$this->var,如果是,private您无法设置它
$var
protected
public
$this->var
private
在构造函数或其他一些成员函数中使用$this:
$this
function __construct() { $this->var = Food::foodFunction(); }
否则,您无法初始化$var为非静态的任何内容。