Home > Backend Development > PHP Tutorial > 为什么用var_dump()打印mysqli对象的时候,结果都是null?

为什么用var_dump()打印mysqli对象的时候,结果都是null?

WBOY
Release: 2016-06-06 20:21:52
Original
1491 people have browsed it

为什么用var_dump()打印mysqli对象的时候,结果都是null?

代码如下:

<code>$mysqli=new mysqli("localhost:3307","root","","test");
var_dump($mysqli);
print_r($mysqli);
</code>
Copy after login
Copy after login

回复内容:

为什么用var_dump()打印mysqli对象的时候,结果都是null?

代码如下:

<code>$mysqli=new mysqli("localhost:3307","root","","test");
var_dump($mysqli);
print_r($mysqli);
</code>
Copy after login
Copy after login

$mysqli=new mysqli("localhost:3306","root","","test");
var_export($mysqli);
echo "
";
var_dump($mysqli);
echo "
";
print_r($mysqli);

返回结果为mysqli::__set_state(array( 'affected_rows' => NULL, 'client_info' => NULL, 'client_version' => NULL, 'connect_errno' => NULL, 'connect_error' => NULL, 'errno' => NULL, 'error' => NULL, 'field_count' => NULL, 'host_info' => NULL, 'info' => NULL, 'insert_id' => NULL, 'server_info' => NULL, 'server_version' => NULL, 'stat' => NULL, 'sqlstate' => NULL, 'protocol_version' => NULL, 'thread_id' => NULL, 'warning_count' => NULL, ))

查了下 var_export
var_export必须返回合法的php代码, 也就是说,var_export返回的代码,可以直接当作php代码赋值个一个变量。 而这个变量就会取得和被var_export一样的类型的值
但是, 当变量类型为resource的时候, 是无法简单copy复制的,所以, 当var_export的变量是resource类型时, var_export会返回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