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.
我想知道是否有像动态类和函数调用这样的东西?
例如,我有这两个操作:
$this->foo->value(); $this->bar->value();
我想这样称呼它:
$this->($var)->value();
现在我正在这样做(但会喜欢上面的方法)
if($var == 'foo') $this->foo->value(); else $this->bar->value();
你几乎拥有它。
$var = 'foo'; $this->$var->value();
相当于
$this->foo->value():
相似地:
$var = 'bar'; $this->foo->$var();
相当于;
$this->foo->bar();