Jump to content

Question about var_dump($object) output


NotionCommotion
Go to solution Solved by requinix,

Recommended Posts

What does the #1 in object(stdClass)#1 (3) {} represent?

<?php
$a = (object) array('a'=>1, 'b'=>2, 'c'=>array("a", "b", "c"));
var_dump($a);
[Michael@devserver react]$ php var_dump.php
object(stdClass)#1 (3) {
  ["a"]=>
  int(1)
  ["b"]=>
  int(2)
  ["c"]=>
  array(3) {
    [0]=>
    string(1) "a"
    [1]=>
    string(1) "b"
    [2]=>
    string(1) "c"
  }
}
[Michael@devserver react]$

Link to comment
Share on other sites

It's a counter PHP manages for object instances - no two that exist at the same time will have the same number.

 

Thanks.  Why doesn't SplObjectStorage use it to identify objects (I believe it uses a hash of the object)?  Other than to PHP, is this number useful?  I guess it can be used when debugging to confirm one is looking at the same object.  Is there any a time one would use this number in a script?

Link to comment
Share on other sites

  • Solution

Why doesn't SplObjectStorage use it to identify objects (I believe it uses a hash of the object)?

That's right, and I don't know. It's quite possible - likely, even - that I don't know the full story behind what the number is and how it works.

 

Other than to PHP, is this number useful?

Only when debugging.

 

I guess it can be used when debugging to confirm one is looking at the same object.

Right.

 

Is there any a time one would use this number in a script?

Nope.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.