cronfy / debug
v0.0.1
2019-08-19 08:16 UTC
Requires
- php: >=5.6.0
This package is auto-updated.
Last update: 2024-09-09 21:58:09 UTC
README
调试辅助函数。
工作原理
D([1, 2, 'foo', 'bar']);
输出
Debug in /app/www/index.php line 7 (start)
Array ( [0] => 1 [1] => 2 [2] => foo [3] => bar )
Debug in /app/www/index.php line 7 (end)
然后结束工作(die())。输出变量快照(print_r()),文件,出错的行。
也可以以 var_dump() 格式输出
D([1, 2, 'foo', 'bar'], 1);
Debug in /app/www/index.php line 7 (start)
array(4) { [0]=> int(1) [1]=> int(2) [2]=> string(3) "foo" [3]=> string(3) "bar" }
Debug in /app/www/index.php line 7 (end)
还有 E() - 与之相同,但不会在输出快照后结束工作。
安装
composer require cronfy/debug
配置
要使用 Debug::D(...) 而不是 D(...) 来调用调试函数,需要在全局命名空间中(比如在 vendor/autoload.php 附近)添加辅助函数
function D($var = null, $vardump = null) { call_user_func_array('\cronfy\debug\Debug::D', [$var, $vardump, (PHP_VERSION_ID >= 70000) ? 1 : 2]); }
默认情况下,调试函数在生产模式下运行,不输出任何数据。要查看快照,需要明确设置调试模式
\cronfy\debug\Debug::$debug = true;
函数
Debug::D($var)- 输出$var并结束工作。Debug::E($var)- 输出$var并继续工作。