当前位置:网站首页>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 .
边栏推荐
- C语言循环语句介绍(foe、while、do...while)
- Fizz gateway secondary development integration tutorial
- 5 points + single gene pan cancer pure Shengxin idea!
- [deep learning][pytorch][original]crnn trains loss on the higher version of pytorch as a solution for Nan
- Opencv learning notes - cv:: mat class
- How to calculate the bandwidth of video transmission? How much bandwidth is required to transmit 4K video?
- Easynvr user login is modified to share the modification process of ip+ user name restriction
- 哪个商业保险养老险好?2022年商业养老保险产品排名
- Opencv optical flow prediction and remap remapping function usage
- 《梦华录》要大结局了,看超前点映不如先来学学它!
猜你喜欢
FreeRTOS overview and experience
[digital ic/fpga] booth multiplier
GTest从入门到入门
Tools and methods - use code formatting tools in source insight
Install Kali on the U disk and persist it
Linker --- linker
软件测试 对前一日函数的基本路径测试
"Meng Hua Lu" is about to have a grand finale. It's better to learn it first than to look ahead!
Programmers spend most of their time not writing code, but...
How stupid of me to hire a bunch of programmers who can only "Google"!
随机推荐
Chenglixin research group of Shenzhen People's hospital proposed a new method of multi group data in the diagnosis and prognosis analysis of hepatocellular carcinoma megps
[206] use PHP language to generate the code of go language
哪个商业保险养老险好?2022年商业养老保险产品排名
GLOG从入门到入门
怎么可以打新债 开户是安全的吗
数据标注科普:十种常见的图像标注方法
[deep learning][pytorch][original]crnn trains loss on the higher version of pytorch as a solution for Nan
Audio knowledge (III) -- MFCCs code implementation
Insurance app aging service evaluation analysis 2022 issue 06
[Architect (Part 41)] installation of server development and connection to redis database
A fault record of misoperation dhclient script
QT -- the qtabwidget supports dragging tabbar items
5W1H talk about open source - what is open source?
Installation and operation of libuv
怎样购买打新债 开户是安全的吗
How to purchase new bonds is it safe to open an account
Tsingsee green rhino video "cloud side end" +ai intelligent security system is integrated into the mainstream development trend
[Old Wei makes machines] issue 090: keyboard? host? Full function keyboard host!
Google Earth Engine(GEE)—如何新增一个图例在Map面板
万名校园开发者花式玩AI,亮点看这张图就够啦!