示例类代码:
<?php
class example
{
public function forExample()
{
return true;
}
}
echo example::forExample(); // result "1"
example::notin(); // notin function is not in the our class
?>
如上文所示;notin函数不在我们的类中,如果被调用的函数不在类中,我想运行如下代码:
<?php
class example
{
public function __construct()
{
require_once 'try.class.php';
}
public function forExample()
{
return true;
}
}
?>
我的第二个问题是:我们如何只为"notin"函数这样做?
我不知道你在要求什么,但我很确定你想要__call
和__callStatic
魔术方法。当(且仅当)在实例/类上调用未定义的方法时,才会调用这些方法。
http://www.php.net/manual/en/language.oop5.overloading.php#object.call