What do the numbers #11 and (0) mean in this var_dump result:
object(PDO)#11 (0) { }
I have a class and I made from it an object and used it in multiple places.
What do the numbers #11 and (0) mean in this var_dump result:
object(PDO)#11 (0) { }
I have a class and I made from it an object and used it in multiple places.
I don't know either, so let's find out together, by looking at the source-code for var_dump! (look for PHP_FUNCTION(var_dump)).
(For TL;DR, jump to the end)
The PHP function var_dump is a wrapper for the C function php_var_dump.
php_var_dump has a switch() statement to generate different output for each of PHP's basic types (numbers, strings, booleans, objects, etc), and we're interested in the object type.
Within the case IS_OBJECT: case we see this:
php_printf("%sobject(%s)#%d (%d) {\n", COMMON, ZSTR_VAL(class_name), Z_OBJ_HANDLE_P(struc), myht ? zend_array_count(myht) : 0);
The #10 in your output comes from the #%d part of the format-string, which is the 3rd C variadic arg, and the (0) is the 4th C variadic arg.
Z_OBJ_HANDLE_P(struc)myht ? zend_array_count(myht) : 0Z_OBJ_HANDLE_P basically returns a unique identifier for an object in PHP (so your PDO instance is the 11th object (I think, see below) created in the processing of this request).
The myht thing is more complicated: but if it's set it means you asked PHP to var_dump an object member property (rather than an object itself), e.g. var_dump( $foo->bar ) instead of var_dump( $foo ). If you aren't referring to an object-property then it just prints 0.
->handle values are determined and what they mean:Z_OBJ_HANDLE_P macro is Z_OBJ_HANDLE(*(zval_p))
Z_OBJ_HANDLE macro is (Z_OBJ((zval)))->handleZ_OBJ macro is (zval).value.objZ_OBJ_HANDLE_P(x) is the same as x.value.obj->handleuint32 handle member (but implemented separately).
_zend_object with _zend_resource in zend_types.hzend_list_insert (which then uses the ZVAL_NEW_RES macro). The ->handle value is the index into that list (though I'm unsure if it starts at 0 or 1 or some other base).class objects ("user types", etc), the zend_objects_store_put function is used which adds the object to the objects_store list and returns the the index of the item in the list (so it's conceptually similar to zend_list_insert).
0, 1, or something else).So object(PDO)#11 (0) { } means:
PDO class.