我有一节课:
class demo {
function newDemo(){
$v=$this->checkDemo;
$v('hello'); // not working this reference, or how to do this?
}
function checkDemo($a){
...
return $a;
}
}
Run Code Online (Sandbox Code Playgroud)
那么,我如何在类中引用checkDemo函数方法呢?
要使对象方法可调用,您需要一个数组.索引0是实例,索引1是方法的名称:
$v = Array($this,"checkDemo");
$v("hello");
Run Code Online (Sandbox Code Playgroud)
编辑:请注意,此功能仅适用于PHP 5.4
你像这样分配它:
$v = 'checkDemo';
$this->$v('hello');
Run Code Online (Sandbox Code Playgroud)
查看文档以获取更多示例。
虽然我不完全确定你为什么要这样做,但就是这样。
| 归档时间: |
|
| 查看次数: |
3757 次 |
| 最近记录: |