What is #<some-number> next to object(someClass) in var_dump of an object? I have an inference. Am I right?

♀尐吖头ヾ 提交于 2019-11-26 20:47:13

That number is Z_OBJ_HANDLE_PP(struc) where struc is a zval which leads to Z_OBJVAL(zval).handle which leads to (zval).value.obj.

See as well http://php.net/manual/en/internals2.variables.intro.php

In short I would say it's the object identifier 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 count of objects ever created.

No, it's an internal reference to the object instance, if you did

var_dump($obj1); 

again, it would still be id #2

EDIT

In the case of your

var_dump(new stdClass);

PHP is creating a new instance of stdClass and dumping it using var_dump, giving you instance #7. However, because this instance is transient (you're not assigning it to any variable) it's being destroyed again immediately afterwards, so object id #7 is available again for allocation to the next object that you create with

$obj6 = new stdClass; 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!