- URL: https://www.laruence.com/en/2008/04/03/15.html
- Please include attribution when republishing.
How the problem was found
While tracing yratings_get_targets, I ran:
error_log(var_export(yblog_mspconfiginit("ratings"),true));
and it kept printing that the return value of yblog_mspconfiginit("ratings") was NULL,
which led me to think the DB connection couldn't be established. That sent me down the wrong path for a whole day.
In the end I discovered this is one of the differences between var_export and var_dump.
Namely:
The cause
var_export must return valid PHP code — that is, the code var_export returns can be assigned directly to a variable as PHP code, and that variable will then hold a value of the same type as the one var_export was given.
- However, when the variable is of type resource, it can't be simply copied. So when var_export is given a resource, var_export returns NULL.
Examples
$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
Be First to Comment