【发布时间】:2013-07-23 21:25:17
【问题描述】:
致命错误:达到“100”的最大函数嵌套级别,正在中止!在第 4 行的 C:\wamp\www\int\system\core\Controller.php 中
Call Stack
# Time Memory Function Location
1 0.0004 364608 {main}( ) ..\index.php:0
2 1.0350 433152 Bootstrap->__construct( ) ..\index.php:11
3 1.0355 438536 Welcome->__construct( ) ..\Bootstrap.php:7
4 1.0355 438536 Controller->__construct( ) ..\welcome.php:4
5 1.0356 438680 View->__construct( ) ..\Controller.php:4
6 1.0356 438680 Controller->__construct( ) ..\View.php:4
错误行:
<?php
class Controller {
function __construct() {
$this->view = new View(); // Error starts here
$this->model = new Model();
$this->tpl = new Template();
$this->input = new Input();
$this->lib = new Library();
$this->session = new Session();
}
}
?>
我将如何解决这个问题?我尝试扩展最大嵌套级别,但每次我将其增加到 200 时,它都会说达到 200 的致命错误,正在中止!
更新:已修复:)
public function __construct() {
self::$instance =& $this;
$this->view = new View;
$this->model = new Model;
$this->tpl = new Template;
$this->input = new Input;
$this->lib = new Library;
$this->session = new Session;
}
public static function &get_instance() {
return self::$instance;
}
在模型中:
function __get($key)
{
$fw =& Controller::get_instance();
return $fw->$key;
}
【问题讨论】:
-
我假设你的循环之一坏了......
-
弄清楚为什么 View 构造函数会尝试构造一个 Controller。
-
您的
View和Controller之间有一个循环引用。 -
好吧,我需要它能够将 $this->view、$this->model 等连接到视图和模型中。视图+模型控制器(以及该文件中的所有其他控制器)不扩展控制器,但我希望能够在视图/模型中使用它们,所以我尝试扩展控制器,我看到它不想玩得很好.
-
正如其他人所建议的,这是一个设计问题。您是否考虑过其他方法?显然你正在撞墙,为什么不简单地从方程中删除墙?