digitalnature/php-ref

PHP 5.3+的print_r/var_dump的更佳替代方案

v1.3 2020-01-28 21:41 UTC

This package is not auto-updated.

Last update: 2024-09-14 15:00:45 UTC


README

REF或r()是PHP中print_r函数的更佳替代方案print_rvar_dump函数。

演示

要求

  • (服务器) PHP 5.3+ (5.4+显示更多信息)
  • (客户端) 任何浏览器,当然不包括IE 8及以下版本

使用Composer安装

将REF添加到您的composer.json

{
    "require": {
        "digitalnature/php-ref": "dev-master"
    }
}

现在运行以下命令告诉Composer下载捆绑包

$ php composer.phar update digitalnature/php-ref

Composer会将捆绑包安装到目录vendor/digitalnature中。

用法

基本示例

// include the class (not needed if project runs with Composer because it's auto-loaded)
require '/full/path/to/ref.php';

// display info about defined classes
r(get_declared_classes());

// display info about global variables
r($GLOBALS);

要使用文本模式打印,可以使用rt()函数代替

rt($var);

要信息输出后终止脚本,请使用按位非运算符

~r($var);   // html
~rt($var);  // text

在前面加上错误控制运算符(@)将返回信息

$output = @r($var);   // html
$output = @rt($var);  // text

键盘快捷键(必须启用javascript)

  • X - 折叠/展开所有级别
  • Ctrl + X - 切换显示状态

要修改全局配置,请调用ref::config()

// example: initially expand first 3 levels
ref::config('expLvl', 3);

您还可以像这样在php.ini文件中添加配置选项

[ref]
ref.expLvl = 3
ref.maxDepth = 4

当前可用的选项及其默认值

类似的项目

待办事项

  • 从父或原型继承缺失的DocBlock注释
  • 重构“气泡”(用于文本模式)
  • 正确缩进多行字符串(文本模式)
  • 将分隔符令牌移动到::before和::after伪元素(HTML模式)

许可

https://open-source.org.cn/licenses/mit-license.html