> Am 02.08.2015 um 19:09 schrieb Derick Rethans <der...@php.net>:
> 
> On Fri, 31 Jul 2015, Julien Pauli wrote:
> 
>> Hi people.
>> 
>> I've been pinged many times to add a new spl_object_id() function to PHP,
>> that would return the internal object handle of an object.
>> 
>> Today, spl_object_hash() partially allows that, but adds many randomness to
>> the result, which is not very cool to use later  (why does it even add
>> randomness ?).
>> 
>> There has been topics about this subject.
>> For example, at http://marc.info/?l=php-internals&m=141814350920452&w=2
>> 
>> 
>> Beeing able to get the object handle back in PHP userland would ease many
>> tools, mainly debug-oriented tools.
>> I know PHPUnit, Symfony and many big projects today make use of
>> spl_object_hash() to identify objects.
>> 
>> I also know people that print_r($an_object) and parse the output just to
>> extract the object handle from there... Crazy isn't it ?
>> Why couldn't we help those people by simply adding a new function that does
>> the job ?
> 
> You realize that these object handles aren't particularly stable? The 
> same object ID can be reused:
> 
> derick@whisky:/tmp $ cat objid.php 
> <?php
> class Foo {}
> $a = new Foo;
> var_dump($a);
> $a = new Foo;
> var_dump($a);
> $a = new Foo;
> var_dump($a);
> 
> derick@whisky:/tmp $ php objid.php 
> class Foo#1 (0) {
> }
> class Foo#2 (0) {
> }
> class Foo#1 (0) {
> }
> 
> You can't deterministically reference an object by it's class and 
> handle... so I also think this implementation detail should not be 
> shared through an API.
> 
> cheers,
> Derick

Ehm, you realize that object id is only reset because the old object is freed? 
As long as the target object is referenced, nothing will have the same object 
id.

Which is why this isn't an issue. Is there any point in having an unique id? 
It's only 32 bit on some systems. When it once overflows, it'd be reused anyway.
What's important is having an exact 1:1 mapping of id and [existing] object. 
Which is all we need.

Bob

Reply via email to