Home  >  Article  >  Backend Development  >  The difference between var_export and var_dump

The difference between var_export and var_dump

angryTom
angryTomforward
2019-10-15 09:16:031556browse

Problem discovery

When tracking yratings_get_targets,

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

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/>

Result:

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

Another example:

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

Result:

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

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!

Statement:
This article is reproduced at:www.laruence.com. If there is any infringement, please contact admin@php.cn delete