post by tommy @ 20 十二月, 2011 21:23
這是早上那個 Gallery 3 與 ZendGuardLoader 一起使用時的問題, 寫了一個小的 test case, 可以重製這個錯誤.
Class File => a.php
<?php
class a {
static public function my_fun()
{
return true;
}
}
?>
Test File => t.php
<?php
class T {
static public function auto_load($class) {
echo "looking for $class\n";
$n = ''.$class.'.php';
if (file_exists($n)) {
echo "loading from file: $n\n";
require_once($n);
return true;
}
return false;
}
}
spl_autoload_register(array('T', 'auto_load'));
// this one work
$class = 'a';
if (method_exists($class, 'my_fun'))
echo "$class.my_fun() exists\n";
else
echo "$class.my_fun() not exists\n";
// this got segmentation fault
$class = 'MY_CLASS_1000';
if (method_exists($class, 'my_fun'))
echo "$class.my_fun() exists\n";
else
echo "$class.my_fun() not exists\n";
spl_autoload_unregister(array('T', 'auto_load'));
?>
正常沒有載入 ZendGuardLoader 時的結果:
mail:/tmp# php -v
PHP 5.3.8-1 with Suhosin-Patch (cli) (built: Nov 23 2011 18:25:58)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
mail:/tmp# php -Cq t.php
looking for a
loading from file: a.php
a.my_fun() exists
looking for MY_CLASS_1000
MY_CLASS_1000.my_fun() not exists
mail:/tmp#
載入 ZendGuardLoader 時的結果:
mail:/tmp# php -v
PHP 5.3.8-1 with Suhosin-Patch (cli) (built: Nov 23 2011 18:25:58)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies
with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
mail:/tmp# php -Cq t.php
looking for a
loading from file: a.php
a.my_fun() exists
looking for MY_CLASS_1000
looking for MY_CLASS_1000
looking for 80fbdj487sxn5
Segmentation fault
mail:/tmp#
在載入 ZendGuardLoader 之後, 會對一個不存在的 class 執行 autoload 函式兩次 (應該算三次吧), 然後會跟著一個亂數名的 class 再執行 autoload 函式一次.... 接著就 segmentation fault 了.
有了這個簡單的 case, 就丟給 Zend 去分析了 (奇怪, 怎麼我開一個新的 support case 都會不成功?... 最後只好丟他們的討論區去), 希望有好消息.