What is the # <some-number> next to the object (someClass) in the var_dump of the object? I have a conclusion. I'm right?
This is the code and its output, which I used for the output below:
class a { public $var1; public $var2; } $obj0 = new a; var_dump($obj0); class b { public $var1; public $var2; public $var3; } $obj1 = new b; var_dump($obj1); $obj2 = new stdClass; var_dump($obj2); $obj3 = new stdClass; var_dump($obj3); $obj4 = new stdClass; var_dump($obj4); $obj5 = new stdClass; var_dump($obj5); var_dump(new stdClass); $obj6 = new stdClass; var_dump($obj6); Exit:
object(a)#1 (2) { ["var1"]=> NULL ["var2"]=> NULL } object(b)#2 (3) { ["var1"]=> NULL ["var2"]=> NULL ["var3"]=> NULL } object(stdClass)#3 (0) { } object(stdClass)#4 (0) { } object(stdClass)#5 (0) { } object(stdClass)#6 (0) { } object(stdClass)#7 (0) { } object(stdClass)#7 (0) { } #<some-number> next to the line object(someClass) in the var_dump object is actually #<count> . Where,
count - the number of objects / zval for objects, regardless of which class it belongs to, which has been created so far. Which continues to receive an increment for each created object and decreases by 1 when the refcount zval reaches zero, i.e. the Garbage Collection.
I'm right?
This is the number Z_OBJ_HANDLE_PP(struc) , where struc is zval , which leads to Z_OBJVAL(zval).handle , which leads to (zval).value.obj .
See also http://php.net/manual/en/internals2.variables.intro.php
In short, I would say that this is the identifier of the object , written in decimal form (ref):
php_printf("%sobject(%s)#%d (%d) {\n", COMMON, class_name, Z_OBJ_HANDLE_PP(struc), myht ? zend_hash_num_elements(myht) : 0); And not the number of objects ever created.
No, this is an internal reference to an instance of an object, if you did
var_dump($obj1); he will still be id # 2
EDIT
In case of your
var_dump(new stdClass); PHP creates a new instance of stdClass and resets it with var_dump, giving you instance # 7. However, since this instance is temporary (you don't assign it to any variable), it is immediately destroyed again, so object identifier # 7 is again available for highlighting the next object that you create with
$obj6 = new stdClass;