我有一个带有私有函数的类,我不想直接调用它。
示例类:
class Importer{
private function import(){}
}
现在我想将传递给__autoload()
的参数发送到Importer
类import
函数。
我也经常知道调用私有函数是不可能的,也不合逻辑,但是您知道有什么解决方案或技巧可以保持import()
私有或防止直接访问吗?
class Importer {
public function __construct() {
spl_autoload_register( array($this, 'import') );
}
private function import($class) {
include $class . '.php';
}
}
$importer = new Importer();
$obj = new testclass();
var_dump($obj);
输出
object(testclass(#2 (0( { }