如何调试PHP脚本?
我知道基本的调试,如使用错误报告。PHPEclipse中的断点调试也非常有用。
在phpStorm或任何其他IDE中调试的最佳方法(就快速和简单而言)是什么?
如何调试PHP脚本?
我知道基本的调试,如使用错误报告。PHPEclipse中的断点调试也非常有用。
在phpStorm或任何其他IDE中调试的最佳方法(就快速和简单而言)是什么?
当前回答
尝试Eclipse PDT来设置具有您提到的调试特性的Eclipse环境。与var_dump的老方法相比,进入代码的能力是一种更好的调试方法,并在各个点打印,以查看流在哪里出错。当所有这些都失败了,虽然,我只有SSH和vim,我仍然var_dump()/die()找到哪里的代码出错。
其他回答
当不能使用Rails时,我经常使用CakePHP。为了调试错误,我通常会在tmp文件夹中找到error.log,然后在终端中使用命令…
tail -f app/tmp/logs/error.log
它可以让你从蛋糕中运行正在发生的事情的对话框,这非常方便,如果你想在代码中输出一些东西,你可以使用。
$this->log('xxxx');
这通常可以让你很好地了解发生了什么。
这是我的调试环境:
error_reporting(-1);
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 0);
assert_options(ASSERT_BAIL, 0);
assert_options(ASSERT_QUIET_EVAL, 0);
assert_options(ASSERT_CALLBACK, 'assert_callcack');
set_error_handler('error_handler');
set_exception_handler('exception_handler');
register_shutdown_function('shutdown_handler');
function assert_callcack($file, $line, $message) {
throw new Customizable_Exception($message, null, $file, $line);
}
function error_handler($errno, $error, $file, $line, $vars) {
if ($errno === 0 || ($errno & error_reporting()) === 0) {
return;
}
throw new Customizable_Exception($error, $errno, $file, $line);
}
function exception_handler(Exception $e) {
// Do what ever!
echo '<pre>', print_r($e, true), '</pre>';
exit;
}
function shutdown_handler() {
try {
if (null !== $error = error_get_last()) {
throw new Customizable_Exception($error['message'], $error['type'], $error['file'], $error['line']);
}
} catch (Exception $e) {
exception_handler($e);
}
}
class Customizable_Exception extends Exception {
public function __construct($message = null, $code = null, $file = null, $line = null) {
if ($code === null) {
parent::__construct($message);
} else {
parent::__construct($message, $code);
}
if ($file !== null) {
$this->file = $file;
}
if ($line !== null) {
$this->line = $line;
}
}
}
集成的调试器,可以在逐步执行代码时观察变量值的变化,这真的很酷。但是,它们确实需要在服务器上安装软件,并在客户机上进行一定数量的配置。两者都需要定期维护以保持良好的工作状态。
print_r易于编写,并保证在任何设置中都能工作。
Print_r (debug_backtrace());
或者类似的东西:-)
PhpEd真的很好。你可以进入/进入/退出函数。你可以运行特别代码,检查变量,改变变量。太神奇了。