Re: Exposing object handles to userland
| From: | Derick Rethans | Date: | Sun, 02 Aug 2015 17:09:16 +0000 |
| Subject: | Re: Exposing object handles to userland | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-87521@lists.php.net to get a copy of this message | ||
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 q
> o‘Ë bÏžùE¼Ó�1http://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