打印变量的相关信息
自动兼容当前脚本所在的环境, 如 cli, php-cgi 等, 不同的环境展示相同的美化效果
在开启命名空间情况下(asf.use_namespace=1)类名为 Asf\Debug\Dump
<?php namespace Asf\Debug; final class Dump { public static string vars(mixed $expression [, mixed $... ]) }
这里简单地做了一个性能对比测试(ab -c50 -n100), 选择了原生PHP var_dump, Asf\Debug\Dump, Symfony\Component\VarDumper
<?php // 公共部分代码 define('VER_STR', 'VERSION_ID_100'); $a_check = array( 'aaa', 'bbb' => array( 'aaa_1' => 100, 'bbb_1' => array( 'ccc_2', 'ccc_3' => 'world', 'ccc_4' => VER_STR ) ), 'a' => false, 'b' => true, 'c' => null, 'd' => 100.05, );
名称 | 美化 | 源代码 | 压测结果 (ab -c50 -n100) |
PHP var_dump | 无 |
<?php // 公共部分代码 for ($i = 0; $i < 1000; $i++) { var_dump($a_check); } |
Total transferred: 35413700 bytes HTML transferred: 35400000 bytes Requests per second: 634.04 [#/sec] (mean) Time per request: 78.859 [ms] (mean) Time per request: 1.577 [ms] (mean, across all concurrent requests) Transfer rate: 219274.10 [Kbytes/sec] received |
Asf\Debug\Dump | 有 |
<?php // 公共部分代码 for ($i = 0; $i < 1000; $i++) { dump::vars($a_check); } |
Total transferred: 173913700 bytes HTML transferred: 173900000 bytes Requests per second: 490.18 [#/sec] (mean) Time per request: 102.004 [ms] (mean) Time per request: 2.040 [ms] (mean, across all concurrent requests) Transfer rate: 832508.68 [Kbytes/sec] received |
Symfony\Component\VarDumper | 有 |
<?php // 公共部分代码 require __DIR__.'/vendor/autoload.php'; for ($i = 0; $i < 1000; $i++) { dump($a_check); } |
Total transferred: 121174116 bytes HTML transferred: 121160416 bytes Requests per second: 27.68 [#/sec] (mean) Time per request: 1806.075 [ms] (mean) Time per request: 36.121 [ms] (mean, across all concurrent requests) Transfer rate: 32760.03 [Kbytes/sec] received |