Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #5738 > unrolled thread

object id - where?

Started by"M. Strobel" <sorry_no_mail_here@nowhere.dee>
First post2012-04-26 11:34 +0200
Last post2012-04-30 14:43 +0200
Articles 7 — 4 participants

Back to article view | Back to comp.lang.php


Contents

  object id - where? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-26 11:34 +0200
    Re: object id - where? Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-26 05:38 -0400
      Re: object id - where? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-26 11:42 +0200
        Re: object id - where? Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-26 20:33 -0400
    Re: object id - where? Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2012-04-27 22:07 +0200
    Re: object id - where? Goran <goran@nospam.com> - 2012-04-30 13:19 +0200
      Re: object id - where? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-30 14:43 +0200

#5738 — object id - where?

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-04-26 11:34 +0200
Subjectobject id - where?
Message-ID<9vsj4kFfumU1@mid.uni-berlin.de>
Hi,

is there something like an object id accessible?

Example: I do this

php > $a = new stdclass;
php > $a->b = new stdclass;
php > var_dump($a);
object(stdClass)#1 (1) {
  ["b"]=>
  object(stdClass)#2 (0) {
  }
}
php >

and var_dump() shows me unique ids of the classes. Is there a function for it?

/Str.

[toc] | [next] | [standalone]


#5740

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-04-26 05:38 -0400
Message-ID<jnb52c$lg2$1@dont-email.me>
In reply to#5738
On 4/26/2012 5:34 AM, M. Strobel wrote:
> Hi,
>
> is there something like an object id accessible?
>
> Example: I do this
>
> php>  $a = new stdclass;
> php>  $a->b = new stdclass;
> php>  var_dump($a);
> object(stdClass)#1 (1) {
>    ["b"]=>
>    object(stdClass)#2 (0) {
>    }
> }
> php>
>
> and var_dump() shows me unique ids of the classes. Is there a function for it?
>
> /Str.

Classes do not have id's.  Objects have unique ids, but they are only 
for reference and can change.

Why would you want such a function?

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#5742

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-04-26 11:42 +0200
Message-ID<9vsjjgFj9mU2@mid.uni-berlin.de>
In reply to#5740
Am 26.04.2012 11:38, schrieb Jerry Stuckle:
> On 4/26/2012 5:34 AM, M. Strobel wrote:
>> Hi,
>>
>> is there something like an object id accessible?
>>
>> Example: I do this
>>
>> php>  $a = new stdclass;
>> php>  $a->b = new stdclass;
>> php>  var_dump($a);
>> object(stdClass)#1 (1) {
>>    ["b"]=>
>>    object(stdClass)#2 (0) {
>>    }
>> }
>> php>
>>
>> and var_dump() shows me unique ids of the classes. Is there a function for it?
>>
>> /Str.
> 
> Classes do not have id's.  Objects have unique ids, but they are only for reference
> and can change.
> 
> Why would you want such a function?
> 

To detect loops in a tree. Just an idea.

I know I can give them an id, but only if it's necessary...

/Str.

[toc] | [prev] | [next] | [standalone]


#5751

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-04-26 20:33 -0400
Message-ID<jncpge$abg$1@dont-email.me>
In reply to#5742
On 4/26/2012 5:42 AM, M. Strobel wrote:
> Am 26.04.2012 11:38, schrieb Jerry Stuckle:
>> On 4/26/2012 5:34 AM, M. Strobel wrote:
>>> Hi,
>>>
>>> is there something like an object id accessible?
>>>
>>> Example: I do this
>>>
>>> php>   $a = new stdclass;
>>> php>   $a->b = new stdclass;
>>> php>   var_dump($a);
>>> object(stdClass)#1 (1) {
>>>     ["b"]=>
>>>     object(stdClass)#2 (0) {
>>>     }
>>> }
>>> php>
>>>
>>> and var_dump() shows me unique ids of the classes. Is there a function for it?
>>>
>>> /Str.
>>
>> Classes do not have id's.  Objects have unique ids, but they are only for reference
>> and can change.
>>
>> Why would you want such a function?
>>
>
> To detect loops in a tree. Just an idea.
>
> I know I can give them an id, but only if it's necessary...
>
> /Str.

I'm not sure the object id remains consistent.  I don't see any reason 
it would change, but I've never seen anything in PHP indicating it has 
to be that way, either.

I'd suggest just sticking your own id in the object.  Then you know what 
you have.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#5767

FromThomas Mlynarczyk <thomas@mlynarczyk-webdesign.de>
Date2012-04-27 22:07 +0200
Message-ID<jneu99$nt9$1@news.albasani.net>
In reply to#5738
M. Strobel schrieb:

> is there something like an object id accessible?

You can use === to check if two variables refer to the same object:

$a = new stdclass;
$a->foo = 42;
$b = new stdclass;
$b->foo = 42;
$c = $a;
var_dump( $a === $b, $a === $c, $b === $c );

Result:
false, true, false

Greetings,
Thomas

-- 
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)

[toc] | [prev] | [next] | [standalone]


#5795

FromGoran <goran@nospam.com>
Date2012-04-30 13:19 +0200
Message-ID<jnlsgm$v0s$1@news.metronet.hr>
In reply to#5738
On 26.4.2012 11:34, M. Strobel wrote:
> is there something like an object id accessible?

Try spl_object_hash()

http://www.php.net/manual/en/function.spl-object-hash.php

[toc] | [prev] | [next] | [standalone]


#5796

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-04-30 14:43 +0200
Message-ID<a07fnrF4hmU1@mid.uni-berlin.de>
In reply to#5795
Am 30.04.2012 13:19, schrieb Goran:
> On 26.4.2012 11:34, M. Strobel wrote:
>> is there something like an object id accessible?
> 
> Try spl_object_hash()
> 
> http://www.php.net/manual/en/function.spl-object-hash.php

I see. One of the 1597 internal functions in my system...

/Str.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web