如果调用的函数丢失,我希望在__construct函数中需要任何文件


if called function is missing, i want to require any file in __construct function

示例类代码:

<?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