Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87566 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13193 invoked from network); 3 Aug 2015 10:27:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Aug 2015 10:27:41 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.180 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.180 mail-wi0-f180.google.com Received: from [209.85.212.180] ([209.85.212.180:33868] helo=mail-wi0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 01/00-13081-B124FB55 for ; Mon, 03 Aug 2015 06:27:40 -0400 Received: by wibud3 with SMTP id ud3so129810367wib.1 for ; Mon, 03 Aug 2015 03:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type:subject:from:date:cc :message-id; bh=+wcfOlVjI1FWTQ4+qGV0z3QiBnsPqH1EwuKpO4Zzjh0=; b=fMS7FYZ44Qpef88OOx1EPY6H3ZPzSqbfq5bj56NWErGY0Ls6x9QHi35SeWfGe4ht+V GOE03KPeDVuFl+bYDCkaJl8Uc4WrLTxq86R2PyAQL4SvM7yaZ9HD1HRansdHkUINfndY L2F35N8Lq1RgblYo8rsFNJUMR6DadJiRtZNwGzmmoIFr05sHgnMBU8dc96MEsO6o2DHB du2pVd7fwjZthCSnGFByfHOOKcFr3pX1YTAFt1GAH9yE02c08iMzwY7znPrnHPAQBh9P wjIpaCPCrBptLw6ZXkZvEEFxF4xBT/skthejMYu2MGtv3mx8ZG2w7XLmsBgBj2dnwNJ9 c6YQ== X-Received: by 10.180.211.196 with SMTP id ne4mr32972845wic.23.1438597656542; Mon, 03 Aug 2015 03:27:36 -0700 (PDT) Received: from [100.75.218.196] ([213.205.194.252]) by smtp.gmail.com with ESMTPSA id w8sm22158691wja.15.2015.08.03.03.27.34 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Aug 2015 03:27:35 -0700 (PDT) User-Agent: K-9 Mail for Android In-Reply-To: References: <024101d0cbaa$f864aa50$e92dfef0$@belski.net> <55BDBE25.5050104@gmail.com> <55BE5B89.5080103@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Mon, 03 Aug 2015 11:27:28 +0100 CC: "internals@lists.php.net" Message-ID: <4557ED13-5446-45F1-8E04-A01F8A066600@gmail.com> Subject: Re: [PHP-DEV] Exposing object handles to userland From: rowan.collins@gmail.com (Rowan Collins) On 3 August 2015 08:20:18 BST, Nicolas Grekas wrote: >2015-08-02 20:03 GMT+02:00 Rowan Collins : > >> On 02/08/2015 18:41, Bob Weinand wrote: >> >>> Some suspicious use of spl_object_hash() out there... >>>> > >>>> >>>>> >> >>>>> >https://github.com/symfony/symfony/blob/master/src/Symfony/Component/VarDumper/Cloner/VarCloner.php >>>>> >>>> > >>>> >Not sure what this one does... but calculations with >spl_object_hash() >>>> >look very suspicious. >>>> >>> Actually, it's doing the right thing… 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. >>> >> >> The right thing for what purpose? Why does it need that ID, rather >than >> the value that spl_object_hash() gave in the first place? Just to be >> prettier to the user? >> > > >For the purpose of providing an id that humans can read and compare, So, yes, just to make it more human friendly. In which case, the actual value doesn't matter, and rather than reverse-engineering the hash, you could just make up your own ID: function my_object_id($obj) { static $hash_to_id=[]; $hash = spl_object_hash($obj); if ( ! array_key_exists($hash, $hash_to_id) ) { $hash_to_id[$hash] = count( $hash_to_id); } return $hash_to_id[$hash]; } (Untested, but pretty much all you need.) Regards, -- Rowan Collins [IMSoP]