当前位置:网站首页>VaR in PHP_ export、print_ r、var_ Differences in dump debugging
VaR in PHP_ export、print_ r、var_ Differences in dump debugging
2022-06-24 12:17:00 【PHP Development Engineer 】
1、output basic type
Code
$n = "test";
var_export($n);
print_r($n);
var_dump($n);
echo '-----------------' . '<br/><br/>';
file_put_contents("index.log", var_export($n, true) . PHP_EOL, FILE_APPEND);
file_put_contents("index.log", print_r($n, true) . PHP_EOL, FILE_APPEND);
file_put_contents("index.log", var_dump($n) . PHP_EOL, FILE_APPEND);result
(1) front end :
'test' test /Users/xjnotxj/Program/PhpstormProject/colin/index.php:9:string 'test' (length=4) ----------------- /Users/xjnotxj/Program/PhpstormProject/colin/index.php:15:string 'test' (length=4)
(2)index.log:
'test' test
2、output array
Code
$arr = array(
"a" => 1,
"b" => "222",
"c" => 3,
);
var_export($arr);
print_r($arr);
var_dump($arr);
echo '-----------------' . '<br/><br/>';
file_put_contents("index.log", var_export($arr, true) . PHP_EOL, FILE_APPEND);
file_put_contents("index.log", print_r($arr, true) . PHP_EOL, FILE_APPEND);
file_put_contents("index.log", var_dump($arr) . PHP_EOL, FILE_APPEND);result
(1) front end :
array ( 'a' => 1, 'b' => '222', 'c' => 3, ) Array ( [a] => 1 [b] => 222 [c] => 3 ) /Users/xjnotxj/Program/PhpstormProject/colin/index.php:13: array (size=3) 'a' => int 1 'b' => string '222' (length=3) 'c' => int 3 ----------------- /Users/xjnotxj/Program/PhpstormProject/colin/index.php:19: array (size=3) 'a' => int 1 'b' => string '222' (length=3) 'c' => int 3
(2)index.log:
array ( 'a' => 1, 'b' => '222', 'c' => 3, ) Array ( [a] => 1 [b] => 222 [c] => 3 )
3、output object
Code
class foo
{
public $n;
public function do_foo()
{
echo "Doing foo." . $this->n;
}
}
$object = new foo;
var_export($object);
print_r($object);
var_dump($object);
echo '-----------------' . '<br/><br/>';
file_put_contents("index.log", var_export($object, true) . PHP_EOL, FILE_APPEND);
file_put_contents("index.log", print_r($object, true) . PHP_EOL, FILE_APPEND);
file_put_contents("index.log", var_dump($object) . PHP_EOL, FILE_APPEND);result
(1) front end :
foo::__set_state(array( 'n' => NULL, )) foo Object ( [n] => ) /Users/xjnotxj/Program/PhpstormProject/colin/index.php:19: object(foo)[1] public 'n' => null ----------------- /Users/xjnotxj/Program/PhpstormProject/colin/index.php:25: object(foo)[1] public 'n' => null
(2)index.log:
foo::__set_state(array( 'n' => NULL, )) foo Object ( [n] => )
summary :
1、 Details of output results : var_export ≈ print_r < var_dump
2、 When debugging , call var_export、print_r、var_dump When , no need Add before echo .
3、var_export,print_r Of The second parameter is true Return value .var_dump I won't support it , So use file_put_contents Do not use... When output debugging var_dump.
4、 It is recommended that the debugging of the development environment be used directly var_dump, You can get detailed debugging information and code line number positioning ; Debugging of production environment var_export or print_r, Remember to set the second parameter to true Convert to return output value , Not directly output to the front-end influence line .
summary
The above is a brief introduction PHP in var_export、print_r、var_dump The difference in debugging , I hope that's helpful , If you have any questions, please leave me a message , Xiaobian will reply to you in time . Thank you very much for Open source dominates Support for !
Complete example :http://github.crmeb.net/u/defu
come from “ Open source world ” , link :https://ym.baisou.ltd/post/676.html, If you want to reprint , Please indicate the source , Otherwise, the legal liability will be investigated .
边栏推荐
- 巧妙构思-铁死亡调节因子分型预后发6+
- Coinbase将推出首个针对零售交易员的加密衍生产品
- [206] use PHP language to generate the code of go language
- How to open a new bond? Is it safe to open an account
- 【Go语言刷题篇】Go从0到入门4:切片的高级用法、初级复习与Map入门学习
- Google Earth engine (GEE) - how to add a legend in the map panel
- 【数字IC/FPGA】Booth乘法器
- Variable parameter template implements max (accepts multiple parameters, two implementation methods)
- Reading at night -- about microservices and containers
- Tsingsee green rhino video "cloud side end" +ai intelligent security system is integrated into the mainstream development trend
猜你喜欢

How stupid of me to hire a bunch of programmers who can only "Google"!

Axi low power interface

Linker --- linker

How can a shell script (.Sh file) not automatically close or flash back after execution?

【直播回顾】战码先锋第七期:三方应用开发者如何为开源做贡献
[Old Wei makes machines] issue 090: keyboard? host? Full function keyboard host!

《opencv学习笔记》-- 感兴趣区域(ROI)、图像混合

FreeRTOS概述与体验

AXI低功耗接口

QT -- the qtabwidget supports dragging tabbar items
随机推荐
QT -- the qtabwidget supports dragging tabbar items
Oxylabs live online: website capture demo
Tsingsee green rhino video "cloud side end" +ai intelligent security system is integrated into the mainstream development trend
How to calculate the bandwidth of video transmission? How much bandwidth is required to transmit 4K video?
Popular science of data annotation: ten common image annotation methods
Coinbase将推出首个针对零售交易员的加密衍生产品
The latest hot spot: the use of copper death related genes for tumor prognosis typing!
Basic path test of software test on the function of the previous day
How to open a new bond? Is it safe to open an account
New progress in the construction of meituan's Flink based real-time data warehouse platform
保险APP适老化服务评测分析2022第06期
Speculation London gold short-term stable money making skills? Where is it safe to fry London gold?
Install Kali on the U disk and persist it
Jenkins performance test
单基因泛癌+简单实验就能发表7分+
What code did the full stack programmer write this month?
[cloud based co creation] interpretation of harmonyos application and service ecology
Why are some old SEO methods still effective?
电商红包雨是如何实现的?拿去面试用(典型高并发)
Opencv learning notes - cv:: mat class