Newsgroups: php.internals,php.internals Path: news.php.net Xref: news.php.net php.internals:87454 php.internals:87455 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95132 invoked from network); 31 Jul 2015 20:01:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Jul 2015 20:01:41 -0000 X-Host-Fingerprint: 68.118.157.39 68-118-157-39.dhcp.mdsn.wi.charter.com Received: from [68.118.157.39] ([68.118.157.39:1253] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8B/01-24609-424DBB55 for ; Fri, 31 Jul 2015 16:01:40 -0400 To: internals@lists.php.net,Julien Pauli , Message-ID: <55BBD28A.5080504@stephencoakley.com> Date: Fri, 31 Jul 2015 14:54:50 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 PHP Internals References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 68.118.157.39 Subject: Re: Exposing object handles to userland From: me@stephencoakley.com (Stephen Coakley) On 07/31/2015 09:23 AM, 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 ? > > Thoughts ? > > > Julien.Pauli > I can think of several use cases why this might be useful, and not just for debugging-related code. It could be used for indexing some sort of complex object storage data structure (if you can't/won't use SplObjectStorage). I can think of a few libraries that us spl_object_hash() to do the same thing but doesn't work well in conjunction with forking (probably due to the randomness factor). +1 -- Stephen Coakley