zend_extension = /usr/lib/php4/20020429/xdebug.so
xdebug.default_enable = On
xdebug.show_exception_trace = On
xdebug.show_local_vars = 1
xdebug.max_nesting_level = 50
xdebug.var_display_max_depth = 6
xdebug.dump_once = On
xdebug.dump_globals = On
xdebug.dump_undefined = On
xdebug.dump.REQUEST = *
xdebug.dump.SERVER = REQUEST_METHOD,REQUEST_URI,HTTP_USER_AGENT
将这些设置(或类似的内容)保存到 php.ini 文件中,然后重新启动 Web 服务器。
解释转储报告
以下示例显示了出错时发生的情况。把您的 “有待改进” 的代码修改为类似清单 5 所示的代码。
清单 5. 修改错误代码
<?php
function deep_end( $count ) {
// add one to the frame count
$count += 1;
if ( $count < 48 ) {
deep_end( $count );
}
else {
trigger_error( "going off the deep end!" );
}
}
// main() is called to start the program,
// so the call stack begins with one frame
deep_end( 1 );
? >
<?php
class Person {
var $name;
var $surname;
var $age;
var $children = array();
function Person( $name, $surname, $age, $children = null) {
$this->name = $name;
$this->surname = $surname;
$this->age = $age;
foreach ( $children as $child ) {
$this->children[] = $child;
}
}
}
$boy = new Person( ''Joe'', ''Smith'', 4 );
$girl = new Person( ''Jane'', ''Smith'', 6 );
$mom = new Person( ''Mary'', ''Smith'', 34, array( $boy, $girl ) );
var_dump( $boy, $mom );
?>
清单 7 显示了 var_dump() 的输出。
清单 7. var_dump() 输出
object(person)
var ''name'' => string ''Joe'' (length=3)
var ''surname'' => string ''Smith'' (length=5)
var ''age'' => int 4
var ''children'' =>
array
empty
object(person)
var ''name'' => string ''Mary'' (length=4)
var ''surname'' => string ''Smith'' (length=5)
var ''age'' => int 34
var ''child