Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87576 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32840 invoked from network); 3 Aug 2015 12:26:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Aug 2015 12:26:14 -0000 Authentication-Results: pb1.pair.com header.from=lisachenko.it@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=lisachenko.it@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.50 as permitted sender) X-PHP-List-Original-Sender: lisachenko.it@gmail.com X-Host-Fingerprint: 209.85.215.50 mail-la0-f50.google.com Received: from [209.85.215.50] ([209.85.215.50:36458] helo=mail-la0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/C3-13081-4ED5FB55 for ; Mon, 03 Aug 2015 08:26:13 -0400 Received: by labgo9 with SMTP id go9so26460091lab.3 for ; Mon, 03 Aug 2015 05:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=pU8ex/qpu6g0WTUNPOpZsdRyVQwH4SzEv04eca/j9G0=; b=g3ZoUIKWdIRchepom1EFAArdB29DoR+SOl/8UwXGR7oMJ2IF4oWCZXGbdrA6TIPLj9 /AiuyfZgAjHpyz+NX9R1AE0zpPVeBgBmvryPo21DROmM4nhgBK+j4CQiny27GN2A1B4z OirIOEWNxZh2A3q3Y0jUcgyLxPr2ZNEEQwv5OHO58o9wTXrILULExtMrumvB2TDUPXcv MGyQ/y/miqnDSiUmfO6sLeXz3TEtY7D7BbF+lB6Dnx9XwlkL6T66UTmDCtOQe7c/kpzv dIkqlOspUYIQ2Yimai2ATxEno79khNkdycGa1gNAp9Fq2XXMriDwGZOcvEyi3lCZNAVN Zh1Q== MIME-Version: 1.0 X-Received: by 10.112.239.43 with SMTP id vp11mr16360887lbc.75.1438604769560; Mon, 03 Aug 2015 05:26:09 -0700 (PDT) Received: by 10.112.72.169 with HTTP; Mon, 3 Aug 2015 05:26:09 -0700 (PDT) In-Reply-To: References: <024101d0cbaa$f864aa50$e92dfef0$@belski.net> <55BDBE25.5050104@gmail.com> <55BE5B89.5080103@gmail.com> Date: Mon, 3 Aug 2015 15:26:09 +0300 Message-ID: To: Nicolas Grekas Cc: Rowan Collins , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a113492b8430c04051c67462a Subject: Re: [PHP-DEV] Exposing object handles to userland From: lisachenko.it@gmail.com (Alexander Lisachenko) --001a113492b8430c04051c67462a Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello, internals! I like the idea to assign a custom identifier to the object, but why this should be only in the core? Java has a method 'hashCode' which can be used to return an unique identifier for specific object. So, my suggestion is to add 'Hashable' interface for that into the PHP. Then, each developer can use a default implementation which will return spl_object_id/spl_object_hash/whatever or implement this interface to control the unique identifier of current object: class Test implements Hashable { private static $objectCounter =3D 100500; private $identifier =3D null; public function __construct() { $this->identifier =3D self::$objectCounter++; } public function hashCode() { return __CLASS__ . ':'. $this->identifier; } } echo spl_object_hash(new Test); // Will return 'Test:100500' This solution is more flexible and can give a freedom for implementations. What do you think about this random thought? Thanks. 2015-08-03 10:20 GMT+03:00 Nicolas Grekas : > 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/VarD= umper/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=E2=80=A6 calculating the value th= e 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, to > easily spot if two objects are identical or not. Try comparing two > spl_object_hashes and you'll understand the need... > > The id as displayed by e.g. var_dump is not an implementation detail that > leaks through it. > It's really an important feature of the output. > > I learned that while implementing VarDumper (see link above), by user > requests. > > Regards, > Nicolas > --001a113492b8430c04051c67462a--