您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
private static $isInLoop = false;
private static $buffer = false;
public static function dumps()
{
$args = func_get_args();
$args_num = func_num_args();
if (self::$buffer && $args_num == 1) {
$args = func_get_args();
$args = isset($args[0]) ? $args[0] : [];
if (!empty($args) && (is_array($args) || is_object($args))) {
$args_num = count($args);
}
}
self::$buffer = false;
for ($i = 0; $i < $args_num; ++$i) {
$param = $args[$i];
$ptype = gettype($param);
switch ($ptype) {
case "NULL":
self::dump_null();
break;
case "boolean":
self::dump_boolean($param);
break;
case "integer":
self::dump_integer($param);
break;
case "double":
self::dump_double($param);
break;
case "string":
self::dump_string($param);
break;
case "array":
self::dump_array($param);
break;
case "object":
self::dump_object($param);
break;
case "resource":
echo "resource";
break;
default:
echo "unknown type";
}
}
}
public static function dumpx()
{
self::$buffer = true;
ob_start();
self::dumps(func_get_args());
$var = ob_get_clean();
return $var;
}
public static function dump_null()
{
echo "NULL";
if (!self::$isInLoop) {
echo "\n";
}
self::$isInLoop = false;
}
public static function dump_boolean($bool)
{
if ($bool) {
echo "bool(true)";
} else {
echo "bool(false)";
}
if (!self::$isInLoop) {
echo "\n";
}
self::$isInLoop = false;
}
public static function dump_integer($int)
{
echo "int($int)";
if (!self::$isInLoop) {
echo "\n";
}
self::$isInLoop = false;
}
public static function dump_double($double)
{
echo "float($double)";
if (!self::$isInLoop) {
echo "\n";
}
self::$isInLoop = false;
}
public static function dump_string($str)
{
$len = strlen($str);
$value = "string($len) \"$str\"";
echo $value;
if (!self::$isInLoop) {
echo "\n";
}
self::$isInLoop = false;
}
public static function dump_array($arr)
{
static $pads = [];
$keys = array_keys($arr);
$len = count($arr);
echo "array($len) {";
array_push($pads, " ");
for ($i = 0; $i < $len; $i++) {
echo "\n", implode('', $pads), "[\"$keys[$i]\"] => ";
$index = $keys[$i];
self::$isInLoop = true;
self::dumps($arr[$index]);
}
array_pop($pads);
$pad = implode('', $pads);
echo "\n{$pad}}";
if ($pad == '') {
echo "\n";
}
}
public static function dump_prop($obj)
{
static $pads = [];
$reflect = new ReflectionClass($obj);
$prop = $reflect->getProperties();
$len = count($prop);
echo "($len) {";
array_push($pads, " ");
for ($i = 0; $i < $len; $i++) {
$index = $i;
if (!$prop[$index]->isPublic()) {
continue;
}
$prop_name = $prop[$index]->getName();
echo "\n", implode('', $pads), "[\"{$prop_name}\"] => ";
self::$isInLoop = true;
self::dumps($prop[$index]->getValue($obj));
}
array_pop($pads);
$pad = implode('', $pads);
echo "\n{$pad}}";
if ($pad == '') {
echo "\n";
}
}
public static function dump_object($obj)
{
static $objId = 1;
$className = get_class($obj);
echo "object($className)#$objId";
$objId++;
self::dump_prop($obj);
}
dumps(new class(),"abc",111);
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。