利用php-console和Chrome开发者工具实现PHP应用的printf

261 阅读1分钟

首先安装PHP-console这个Chrome扩展应用:

然后安装服务器端的库文件:github.com/barbushin/p…

用PHP的composer安装:
composer require php-console/php-console

如何在PHP代码里使用这些库文件:

首先用require引入__autoload.php:

获得PhpConsole的handler句柄,调用start方法后即可使用:
$handler = PhpConsole\Handler::getInstance();
$handler->start();

一些常用的打印方式:

带标签打印效果:

$handler->debug(‘called from handler debug’, ‘some.three.tags’);

直接打印:
PhpConsole\Connector::getInstance()->getDebugDispatcher()->dispatchDebug(‘called from debug dispatcher without tag s’);

还有一种缩略形式:

PhpConsole\Helper::register(); // required to register PC class in global namespace, must be called only once - 注册PC这个namespace

PC::debug(‘called from PC::debug()’, ‘db’);
PC::db(‘called from PC::__callStatic()’); // means “db” will be handled as debug tag

打印对象:

输出:

要获取更多Jerry的原创文章,请关注公众号"汪子熙":