Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87522 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85281 invoked from network); 2 Aug 2015 17:41:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Aug 2015 17:41:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=bobwei9@hotmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=bobwei9@hotmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.55.111.155 as permitted sender) X-PHP-List-Original-Sender: bobwei9@hotmail.com X-Host-Fingerprint: 65.55.111.155 blu004-omc4s16.hotmail.com Received: from [65.55.111.155] ([65.55.111.155:52031] helo=BLU004-OMC4S16.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/73-55344-5665EB55 for ; Sun, 02 Aug 2015 13:41:59 -0400 Received: from BLU436-SMTP102 ([65.55.111.136]) by BLU004-OMC4S16.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Sun, 2 Aug 2015 10:41:53 -0700 X-TMN: [xwRtlhtGH0cA5xph9vCrdsN0kzLA0Dn7] X-Originating-Email: [bobwei9@hotmail.com] Message-ID: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) In-Reply-To: <55BDBE25.5050104@gmail.com> Date: Sun, 2 Aug 2015 19:41:48 +0200 CC: Anatol Belski , Nicolas Grekas , Julien Pauli , PHP Internals , Sebastian Bergmann , "Ivan Enderlin@Hoa" , contact@jubianchi.fr Content-Transfer-Encoding: quoted-printable References: <024101d0cbaa$f864aa50$e92dfef0$@belski.net> <55BDBE25.5050104@gmail.com> To: Stanislav Malyshev X-Mailer: Apple Mail (2.2098) X-OriginalArrivalTime: 02 Aug 2015 17:41:51.0575 (UTC) FILETIME=[83C51670:01D0CD4A] Subject: Re: [PHP-DEV] Exposing object handles to userland From: bobwei9@hotmail.com (Bob Weinand) As I describe below, I agree with Nikita on spl_object_id(). > Am 02.08.2015 um 08:52 schrieb Stanislav Malyshev = : >=20 > Hi! >=20 > Some suspicious use of spl_object_hash() out there... >=20 >> = https://github.com/symfony/symfony/blob/master/src/Symfony/Component/VarDu= mper/Cloner/VarCloner.php >=20 > Not sure what this one does... but calculations with spl_object_hash() > look very suspicious. Actually, it's doing the right thing=E2=80=A6 calculating the value the = object id is xor'ed with (as we know that consecutively defined objects = have consecutive ids). It's relying on the implementation of spl_object_hash() and will even = continue to work when we remove that part of randomness as that value = it's xor'ed with is then nothing else than 0. That's why we should expose spl_object_id()=E2=80=A6 so that such hacks = are unnecessary. >> = https://github.com/horde/horde/blob/master/imp/lib/Factory/MimeViewer.php >=20 > This one _might_ be doing it right, but not sure as basing caching > instances on hash of a (mutable) object may produce weird results. It works and I'm using it that way too=E2=80=A6 that's currently what = spl_object_hash is good for. The only issue is when it overflows after = 2^32 objects. Though it isn't an issue on 64 bit systems=E2=80=A6 >> = https://github.com/horde/horde/blob/master/framework/Support/lib/Horde/Sup= port/Randomid.php >=20 > Oh wow, what's going on there? That's obviously not a proper use of > spl_object_hash(). Yup, that one is misuse as source of entropy=E2=80=A6 while it doesn't = really provide much more entropy as it's internally anyway xor'ed with = mt_rand(). >> = https://github.com/WordPress/WordPress/blob/master/wp-includes/plugin.php >=20 > I guess this one is wrong too, as it mentions storage, and storing > object ID is pointless. Maybe I am misunderstanding what "storage" = means > there. The storage is only used in case spl_object_hash() does not exist for = trying to get an unique identifier for that object (Wordpress has 5.2 = compatibility, yeah=E2=80=A6). The object id / hash is basically just an identifier for an object in = PHP, just like we sometimes put pointers in e.g. a binary tree to easily = map two pointers together in C. > --=20 > Stas Malyshev > smalyshev@gmail.com Bob=