Home > Backend Development > PHP Tutorial > Do you know the difference between the output of php var_export and var_dump?

Do you know the difference between the output of php var_export and var_dump?

怪我咯
Release: 2023-03-12 20:16:01
Original
1195 people have browsed it

var_export must return legal php code, that is to say, the code returned by var_export can be directly assigned to a variable as a php code. And this variable will get the same type of value as var_export

Problem discovery
When tracking yratings_get_targets,
error_log (var_export(yblog_mspconfiginit("ratings"),true)); always prints out that the return value of yblog_mspconfiginit("ratings") is NULL

, which leads me to think that the connection to the DB cannot be established, which is wrong. Been on the road for a day.
Finally I discovered that this is one of the differences between var_export and var_dump

This is:
Cause of the problem
var_export must return legal PHP code, that is to say, the code returned by var_export can be directly assigned to a variable as PHP code. And this variable will get the same type of value as var_export

However, when the variable type is resource, it cannot be simply copycopied, so , When the variable of var_export is of resource type, var_export will return NULL

Instance

$res = yblog_mspconfiginit("ratings");
var_dump($res);
var_export($res);结果:
resource(1) of type (yahoo_yblog)
NULL再比如:
$res = fopen('status.html', 'r');
var_dump($res);
var_export($res);结果:
resource(2) of type (stream)
NULL
Copy after login


The above is the detailed content of Do you know the difference between the output of php var_export and var_dump?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template