Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87523 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88844 invoked from network); 2 Aug 2015 17:46:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Aug 2015 17:46:25 -0000 Authentication-Results: pb1.pair.com header.from=bobwei9@hotmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=bobwei9@hotmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.55.111.90 as permitted sender) X-PHP-List-Original-Sender: bobwei9@hotmail.com X-Host-Fingerprint: 65.55.111.90 blu004-omc2s15.hotmail.com Received: from [65.55.111.90] ([65.55.111.90:54568] helo=BLU004-OMC2S15.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 13/24-55344-C675EB55 for ; Sun, 02 Aug 2015 13:46:22 -0400 Received: from BLU436-SMTP172 ([65.55.111.71]) by BLU004-OMC2S15.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Sun, 2 Aug 2015 10:46:17 -0700 X-TMN: [GM0WQwLTDlRhyjY4ZJyDmV6fh/JpZad5] X-Originating-Email: [bobwei9@hotmail.com] Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_BF0A4AB2-9A55-4C01-BFDC-DFBBF9B37F0A" MIME-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) In-Reply-To: Date: Sun, 2 Aug 2015 19:46:12 +0200 CC: Julien Pauli , PHP Internals References: To: Derick Rethans X-Mailer: Apple Mail (2.2098) X-OriginalArrivalTime: 02 Aug 2015 17:46:15.0738 (UTC) FILETIME=[213929A0:01D0CD4B] Subject: Re: [PHP-DEV] Exposing object handles to userland From: bobwei9@hotmail.com (Bob Weinand) --Apple-Mail=_BF0A4AB2-9A55-4C01-BFDC-DFBBF9B37F0A Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="us-ascii" > Am 02.08.2015 um 19:09 schrieb Derick Rethans : >=20 > On Fri, 31 Jul 2015, Julien Pauli wrote: >=20 >> Hi people. >>=20 >> 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. >>=20 >> 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 ?). >>=20 >> There has been topics about this subject. >> For example, at = http://marc.info/?l=3Dphp-internals&m=3D141814350920452&w=3D2 >>=20 >>=20 >> 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. >>=20 >> 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 ? >=20 > You realize that these object handles aren't particularly stable? The=20= > same object ID can be reused: >=20 > derick@whisky:/tmp $ cat objid.php=20 > class Foo {} > $a =3D new Foo; > var_dump($a); > $a =3D new Foo; > var_dump($a); > $a =3D new Foo; > var_dump($a); >=20 > derick@whisky:/tmp $ php objid.php=20 > class Foo#1 (0) { > } > class Foo#2 (0) { > } > class Foo#1 (0) { > } >=20 > You can't deterministically reference an object by it's class and=20 > handle... so I also think this implementation detail should not be=20 > shared through an API. >=20 > 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= --Apple-Mail=_BF0A4AB2-9A55-4C01-BFDC-DFBBF9B37F0A--