zoukankan      html  css  js  c++  java
  • dump调试函数

    //dump调试函数
    if (!function_exists('dump')) {
    /*
    * dump调试函数
    */
    function dump($var)
    {
    $traces = debug_backtrace();
    foreach ($traces as $trace) {
    if (isset($trace['function']) && in_array($trace['function'], array('dump'))) {
    echo '<small>' . $trace['file'] . ':' . $trace['line'] . '</small>' . " ";
    break;
    }
    }
    array_map(function ($var) {
    ob_start();
    var_dump($var);
    $output = ob_get_clean();
    if (!extension_loaded('xdebug')) {
    $output = preg_replace('/]=> (s+)/m', '] => ', $output);
    echo '<pre>' . htmlspecialchars($output, ENT_QUOTES) . '</pre>';
    } else {
    $traces = debug_backtrace();
    foreach ($traces as $trace) {
    if (isset($trace['function']) && in_array($trace['function'], array('dump'))) {
    echo preg_replace('/<small>[^>]*:d+:</small> ? ?/i', '<small style="color:#999;">→</small> ', $output);
    break;
    }
    }
    }
    }, func_get_args());
    }
    }

    调用:
    dump(11,22,[3,4],["a"=>5,"b"=>6], new stdClass());
    输出:
  • 相关阅读:
    上下文管理
    复习1
    描述符
    迭代器斐波那契数列
    迭代器协议
    __call__ 方法
    析构方法__del__
    __module__和class
    1.8命令执行顺序控制与管道(学习过程)
    1.7文件系统操作与磁盘管理(学习过程)
  • 原文地址:https://www.cnblogs.com/wish123/p/6708140.html
Copyright © 2011-2022 走看看