Home > Backend Development > PHP Tutorial > php var_export与var_dump 输出的不同_PHP

php var_export与var_dump 输出的不同_PHP

WBOY
Release: 2016-06-01 12:02:24
Original
954 people have browsed it

问题发现
在跟踪yratings_get_targets的时候,
error_log(var_export(yblog_mspconfiginit("ratings"),true));老是打印出yblog_mspconfiginit(“ratings”)的返回是NULL

导致我以为是无法建立和DB的连接,走错路了一天。
最后才发现,这是var_export和var_dump的区别之一

这就是:
问题原因
var_export必须返回合法的php代码, 也就是说,var_export返回的代码,可以直接当作php代码赋值个一个变量。 而这个变量就会取得和被var_export一样的类型的值

但是, 当变量类型为resource的时候,是无法简单copy复制的,所以, 当var_export的变量是resource类型时, var_export会返回NULL

实例
$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

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