Home > Backend Development > PHP Tutorial > The difference between var_export and var_dump

The difference between var_export and var_dump

angryTom
Release: 2023-04-07 15:58:01
forward
1666 people have browsed it

Problem discovery

When tracking yratings_get_targets,

error_log(var_export(yblog_mspconfiginit("ratings"),true));<br/>
Copy after login

always prints out that the return value of yblog_mspconfiginit("ratings") is NULL

As a result, I thought that the connection to the DB could not be established, and I went on the wrong path 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 Returns legal PHP code. In other words, 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 copied. Therefore, when the variable of var_export is of resource type, var_export will Return NULL

Instance

$res = yblog_mspconfiginit("ratings");<br/>var_dump($res);<br/>var_export($res);<br/>
Copy after login

Result:

resource(1) of type (yahoo_yblog)<br/>NULL<br/>
Copy after login

Another example:

$res = fopen(&#39;status.html&#39;, &#39;r&#39;);<br/>var_dump($res);<br/>var_export($res);<br/>
Copy after login

Result:

resource(2) of type (stream)<br/>NULL<br/>
Copy after login

For more PHP related knowledge, please visit PHP Chinese website!

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

Related labels:
source:www.laruence.com
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