Php 如果调用的函数丢失,我需要_构造函数中的任何文件
示例类代码:Php 如果调用的函数丢失,我需要_构造函数中的任何文件,php,oop,class,Php,Oop,Class,示例类代码: <?php class example { public function forExample() { return true; } } echo example::forExample(); // result "1" example::notin(); // notin function is not in the our class ?> 如上所述;notin函数不在我们的类中,如果调用的函数不在类中,我希望按如下方式运行代码: <?p
<?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”函数执行此操作?我不知道您要求的是什么,但我很确定您需要
\u调用
和\u调用静态
魔术方法。当(且仅当)您对实例/类调用未定义的方法时,才会调用这些方法
如果您试图重新声明
示例
类,则不能。好的,那么我可以在_构造中调用函数名吗?@Yusuf我不太确定您要的是什么。如果您想通过要求另一个类来扩展该类的功能,那么它将不起作用。这不是使用require
的方式。