当前位置:网站首页>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 .
边栏推荐
- 《opencv学习笔记》-- 矩阵归一化 normalize()函数
- 哪个商业保险养老险好?2022年商业养老保险产品排名
- How does wechat and QQ chat work? So simple!!!
- 怎样申购打新债 开户是安全的吗
- [mysql_16] variables, process control and cursors
- 广发证券靠谱吗?开证券账户安全吗?
- 数据标注科普:十种常见的图像标注方法
- Istio best practice: graceful termination
- Google Earth engine (GEE) - how to add a legend in the map panel
- 深圳市人民医院程立新课题组提出多组学数据在肝细胞癌的诊断与预后分析的新方法meGPS
猜你喜欢

GLOG从入门到入门
[Architect (Part 41)] installation of server development and connection to redis database

Axi low power interface

Ten thousand campus developers play AI in a fancy way. It's enough to see this picture!

"Meng Hua Lu" is about to have a grand finale. It's better to learn it first than to look ahead!

GLOG from getting started to getting started

我真傻,招了一堆只会“谷歌”的程序员!

How is the e-commerce red envelope realized? For interview (typical high concurrency)

How to develop hospital information system (his) with SMS notification and voice function

《opencv学习笔记》-- 分离颜色通道、多通道混合
随机推荐
New progress in the construction of meituan's Flink based real-time data warehouse platform
[206] use PHP language to generate the code of go language
美团基于 Flink 的实时数仓平台建设新进展
Database migration tool flyway vs liquibase (II)
Why does the virtual machine Ping the host but not the virtual machine
The latest hot spot: the use of copper death related genes for tumor prognosis typing!
Listed JD Logistics: breaking through again
Realization of alarm clock with AHK
How to develop mRNA vaccine? 27+ pancreatic cancer antigen and immune subtype analysis to tell you the answer!
Variable parameter template implements max (accepts multiple parameters, two implementation methods)
GLOG从入门到入门
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map
How to calculate the bandwidth of video transmission? How much bandwidth is required to transmit 4K video?
11+! Methylation modification patterns based on m6A regulatory factors in colon cancer are characterized by different tumor microenvironment immune spectra
Reading at night -- about microservices and containers
LS-DYNA新手入门经验
我真傻,招了一堆只会“谷歌”的程序员!
Tsingsee green rhino video "cloud side end" +ai intelligent security system is integrated into the mainstream development trend
How to develop hospital information system (his) with SMS notification and voice function
Is it safe to open an account for how many new bonds you can apply for