这个班是下一个
namespace Core;
class RequestHandler{
protected $app;
public function RequestHandler($app){
echo "EEE";
$this->app = $app;
}
}
初始化是
$requestHandler = new Core\RequestHandler($app);
我不知道为什么它没有显示任何东西,但如果我将构造函数更改为__construct,一切正常.
我正在使用PHP 5.6.20,我知道它也应该按名称执行构造函数.
解决方法:
检查示例here:
<?PHP
namespace Foo;
class Bar {
public function Bar() {
// treated as constructor in PHP 5.3.0-5.3.2
// treated as regular method as of PHP 5.3.3
}
}
?>
Warning
Old style constructors are DEPRECATED in PHP 7.0, and will be removed in a future version. You should always use __construct() in new code.
As of PHP 5.3.3, methods with the same name as the last element of a namespaced class name will no longer be treated as constructor. This change doesn’t affect non-namespaced classes.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。