Skip to content

Commit

Permalink
Fixed Bug #70913 (Segfault while new Yaf_Controller)
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Nov 14, 2015
1 parent 14086e7 commit 632c0ad
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
51 changes: 51 additions & 0 deletions tests/bug70913.phpt
@@ -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
2 changes: 1 addition & 1 deletion yaf_controller.c
Expand Up @@ -549,7 +549,7 @@ zend_function_entry yaf_controller_methods[] = {
PHP_ME(yaf_controller, redirect, yaf_controller_redirect_arginfo,ZEND_ACC_PUBLIC)
PHP_ME(yaf_controller, getInvokeArgs,yaf_controller_void_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_controller, getInvokeArg, yaf_controller_getiarg_arginfo,ZEND_ACC_PUBLIC)
PHP_ME(yaf_controller, __construct, NULL, ZEND_ACC_CTOR|ZEND_ACC_FINAL|ZEND_ACC_PUBLIC)
PHP_ME(yaf_controller, __construct, NULL, ZEND_ACC_CTOR|ZEND_ACC_FINAL|ZEND_ACC_PRIVATE)
PHP_ME(yaf_controller, __clone, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
{NULL, NULL, NULL}
};
Expand Down

11 comments on commit 632c0ad

@80520997
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

鸟哥。你对这个问题解决的方式太过粗暴。在我看来感觉就是没有解决。难道这个问题就不能从实质上面干掉吗?是什么原因导致的呢?难道Yaf_Controller_Abstract的设计就是不能允许多个实例存在吗?是内部使用了静态、全局变量还是什么原因呀?

@80520997
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

关键是这样一来我以前的项目都用不了了。我的项目一直是linux上面跑的。就没在乎这个问题。这两天觉得在服务器上面开发太麻烦了想在本地弄个环节开发。可是发现不能就找你反馈了。可是如果我现在已更新这个扩展点话。由于构造函数做成了私有更不就运行不了来。真个项目都是这么来多。我要哭死了!!
鸟哥还是想个更周全大方式解决一下吧

@laruence
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

controller不容许你自己实例化啊,你的场景是啥样的?

@80520997
Copy link

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子类来处理具体业务逻辑

@80520997
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果不允许实例化的话这个类就没办法向前兼容了。它原来是public的。我怀疑别人也有可能用了。类似我的用法。倒是肯定都会有问题的。

我是不明白这个为什么实例化会导致进程崩溃。鸟哥,没什么办法在根源上面解决吗?

@laruence
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你可以用forward,不过好的我考虑下

@80520997
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我的程序用别的办法变通了。不过我觉得这个类应该能够被开发人员自由实例化使用是有价值的。
感谢鸟哥

@80520997
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对了鸟哥。我觉得让Yaf_Controller_Abstract类让用户能够自定义__call魔术方法是有意义多。现在貌似也不行

@laruence
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@80520997 不行是故意的, 对外的入口, 可不能太随意....... 你要想实现__call, 你完全可以用rewrite啊....

@80520997
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我用rewrite把请求指到一个方法上面去了。这个方法的作用在项目里类似__call了

@laruence
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

恩, 这就行了啊, 框架还是要严格点... PS: 我刚刚重新修复了下这个问题, 容许你实例化controller

Please sign in to comment.