PHP命名空间里的静态方法 能不能动态调用?
大家讲道理
大家讲道理 2017-04-10 14:39:01
0
2
309

File1:

// file1.php
namespace Common\Model;

class ArticleModel {
    static function save($id=0) {
        die('xxx');
    }
}

File2:

// file2
namespace Admin\Controller;
include('./file1.php');
$model = 'ArticleModel';
$call = "\\Common\\Model\\$model::save";
$call(123123);

这种方法 我试了,不能调用。
是不是静态方法 不支持动态调用?
还是有别的方式可以调用?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
巴扎黑
namespace Admin\Controller;  
include('./file1.php');  
$fqcn = '\\Common\\Model\\AritcleModel';  
$func = 'save';  
$fqcn::$func(123123);  
PHPzhong
$model = 'ArticleModel';
$call = "\\Common\\Model\\{$model}";

call_user_func_array(array($call, 'save'), array(123123));
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template