Search code examples
phpobjectidentifier

PHP Object () identifier


What is the name of the integer between brackets in a var_dump of an object. And how do I acces it with PHP?

I'm referring to the (3) in the next example.

    object(SimpleXMLElement)#18 (3) {
       ["ID"]=>
      string(3) "xx"
       ["Name"]=>
       string(25) "xx"
       ["Date"]=>
       string(10) "xx"
    }

Solution

  • this is the number of properties of an object. to count this, you can cast your object to an array and use count():

    $number = count((array)$object);
    

    EDIT: i did a small test (see at codepad) wich prooves that casting to an array is what you want to do instead of using get_object_vars() as others mentioned because the later one doesn't count private properties while array-casting as well as var_dump do count these.