Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Bug #70913 (Segfault while new Yaf_Controller)
- Loading branch information
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--TEST-- | ||
Bug #70913 (Segfault while new Yaf_Controller) | ||
--SKIPIF-- | ||
<?php if (!extension_loaded("yaf")) print "skip"; ?> | ||
--INI-- | ||
yaf.use_spl_autoload=1 | ||
yaf.lowcase_path=0 | ||
yaf.throw_exception=0 | ||
yaf.catch_exception=1 | ||
yaf.use_namespace=0 | ||
--FILE-- | ||
<?php | ||
require "build.inc"; | ||
startup(); | ||
|
||
$config = array( | ||
"application" => array( | ||
"directory" => APPLICATION_PATH, | ||
), | ||
); | ||
|
||
file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP | ||
<?php | ||
class IndexController extends Yaf_Controller_Abstract { | ||
public function indexAction() { | ||
new SecondController(\$this->getRequest(), \$this->getResponse(), \$this->getView()); | ||
} | ||
} | ||
PHP | ||
); | ||
|
||
file_put_contents(APPLICATION_PATH . "/controllers/Second.php", <<<PHP | ||
<?php | ||
class SecondController extends Yaf_Controller_Abstract { | ||
} | ||
PHP | ||
); | ||
|
||
file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "Okey"); | ||
|
||
$app = new Yaf_Application($config); | ||
$response = $app->run(); | ||
echo "Okey"; | ||
?> | ||
--CLEAN-- | ||
<?php | ||
require "build.inc"; | ||
shutdown(); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Call to private Yaf_Controller_Abstract::__construct() from context 'IndexController' in %sIndex.php on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
632c0ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
鸟哥。你对这个问题解决的方式太过粗暴。在我看来感觉就是没有解决。难道这个问题就不能从实质上面干掉吗?是什么原因导致的呢?难道Yaf_Controller_Abstract的设计就是不能允许多个实例存在吗?是内部使用了静态、全局变量还是什么原因呀?
632c0ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
关键是这样一来我以前的项目都用不了了。我的项目一直是linux上面跑的。就没在乎这个问题。这两天觉得在服务器上面开发太麻烦了想在本地弄个环节开发。可是发现不能就找你反馈了。可是如果我现在已更新这个扩展点话。由于构造函数做成了私有更不就运行不了来。真个项目都是这么来多。我要哭死了!!
鸟哥还是想个更周全大方式解决一下吧
632c0ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
controller不容许你自己实例化啊,你的场景是啥样的?
632c0ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我是在外面弄了一个Yaf_Controller_Abstract的实例来捕获所有的请求。然后在根据请求实例化新的Yaf_Controller_Abstract子类来处理具体业务逻辑
632c0ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果不允许实例化的话这个类就没办法向前兼容了。它原来是public的。我怀疑别人也有可能用了。类似我的用法。倒是肯定都会有问题的。
我是不明白这个为什么实例化会导致进程崩溃。鸟哥,没什么办法在根源上面解决吗?
632c0ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你可以用forward,不过好的我考虑下
632c0ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我的程序用别的办法变通了。不过我觉得这个类应该能够被开发人员自由实例化使用是有价值的。
感谢鸟哥
632c0ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对了鸟哥。我觉得让Yaf_Controller_Abstract类让用户能够自定义__call魔术方法是有意义多。现在貌似也不行
632c0ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@80520997 不行是故意的, 对外的入口, 可不能太随意....... 你要想实现__call, 你完全可以用rewrite啊....
632c0ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我用rewrite把请求指到一个方法上面去了。这个方法的作用在项目里类似__call了
632c0ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
恩, 这就行了啊, 框架还是要严格点... PS: 我刚刚重新修复了下这个问题, 容许你实例化controller