Question about var_dump output
When I var_dump
an开发者_开发技巧 object, the output looks like this:
object(XCTemplate)#2477 (4) {
["id"]=>
string(1) "1"
["attributes"]=>
array(0) {
}
["db_table_name"]=>
string(14) "template_names"
["cache"]=>
array(0) {
}
}
XCTemplate
is its class, of course, but what does the integer (here: 2477) after the # mean?
It's a unique id associated with that particular instance of XCTemplate
. AFAIK this is not documented, and also there is no way to get it (other than using var_dump()
); and I've looked at the Reflection
class.
From what I've seen:
- The ids are unique to every instantiation; starting at 1 and incrementing by 1 with every new object. This includes every object; they don't have to be of the same class.
- Destroying an instance (eg: through
unset
) frees up its id and the next instantiated object can (and will) use it. It's not related to the variable; eg:
$foo = new Foo(); var_dump($foo); $foo = new Foo(); var_dump($foo);
Will produce different id's for different instantiations.
This is not the same as resource ids, where you can just convert to
int
to get the id:$resource= curl_init(); var_dump($resource); // resource #1 of type curl print(intval($resource)); // 1 print((int) $resource); // 1
精彩评论