Home >Backend Development >PHP Tutorial >The difference between php var_export and var_dump output_PHP tutorial
Problem Found
When tracking yratings_get_targets,
error_log(var_export(yblog_mspconfiginit("ratings"),true)); always prints out yblog_mspconfiginit( "ratings") returns 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 return legal php code, that is to say, the code returned by var_export can be directly assigned as php code a variable. And this variable will get the same type of value as var_export
However, when the variable type is resource, it cannot be copied simply. Therefore, when the variable of var_export is of resource type, var_export will return NULL
Example
$res = yblog_mspconfiginit("ratings");
var_dump($res);
var_export($res); Result:
resource(1) of type (yahoo_yblog)
NULL Another example:
$res = fopen('status.html', 'r');
var_dump($res);
var_export($res); Result:
resource(2) of type (stream)
NULL