使用dump函数,给php加断点测试

yipeiwu_com5年前PHP代码库
复制代码 代码如下:

function dump($var, $echo=true,$label=null, $strict=true)
{
    $label = ($label===null) ? '' : rtrim($label) . ' ';
    if(!$strict) {
        if (ini_get('html_errors')) {
            $output = print_r($var, true);
            $output = "<pre>".$label.htmlspecialchars($output,ENT_QUOTES)."</pre>";
        } else {
            $output = $label . " : " . print_r($var, true);
        }
    }else {
        ob_start();
        var_dump($var);
        $output = ob_get_clean();
        if(!extension_loaded('xdebug')) {
            $output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output);
            $output = '<pre>'. $label. htmlspecialchars($output, ENT_QUOTES). '</pre>';
        }
    }
    if ($echo) {
        echo($output);
        return null;
    }else
        return $output;
}

相关文章

php-fpm超时时间设置request_terminate_timeout资源问题分析

php-fpm超时时间设置request_terminate_timeout资源问题分析

php日志中有一条超时的日志,但是我request_terminate_timeout中设置的是0,理论上应该没有超时时间才对。 PHP Fatal error: Maximum exe...

php中变量及部分适用方法

变量:$_SERVER,         在   PHP ...

PHP设计模式之装饰者模式

PHP设计模式之装饰者模式

介绍 装饰者模式动态地将责任附加到对象上。若要扩展功能,装饰者提供了比继承更有弹性的替代方案。 思维导图   有这样一个项目,做一个餐厅订餐系统。起初的代码结构是这样的。前...

在Windows系统下使用PHP生成Word文档的教程

在Windows系统下使用PHP生成Word文档的教程

准备工作 首先,请确保在你的Windows系统中已经安装并配置好了一个典型的WAMP环境。由于Interop纯粹是一个Windows的特性,我们将在Windows平台下搭建Apache和...

深入理解:单一入口、MVC、ORM、CURD、ActiveRecord概念

MVC MVC是一个设计模式,它强制性的使应用程序的输入、处理和输出分开。使用MVC应用程序被分成三个核心部件:模型(M)、视图(V)、控制器(C),它们各自处理自己的任务。 视图 :...