Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79302 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8301 invoked from network); 28 Nov 2014 23:20:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Nov 2014 23:20:55 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.44 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.44 mail-wg0-f44.google.com Received: from [74.125.82.44] ([74.125.82.44:48098] helo=mail-wg0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3A/67-59154-65309745 for ; Fri, 28 Nov 2014 18:20:54 -0500 Received: by mail-wg0-f44.google.com with SMTP id b13so9871382wgh.3 for ; Fri, 28 Nov 2014 15:20:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=NKnPpEwv0v+rZqxnpGxMmQ06LHYGbUFsplzctV2XfnY=; b=0N7gnwWuAiVfNzOepNmwUbwmPPGGqhEriV/UKlc3Zb+n1TbxrCkUJUQKZzaAKiNcG6 GtPtWtii5NXUPbFF6EG+f9gigdCNFGHDDALMItXFWr2CEA0b9mYzg5hpBWrbDBgt6ChR pD4LgvCaXp4+YQqUt98F35LUiglABLM2nwRDYtbObCp1jMzwrs1CqJP0tx4MjBqE7URi GNlePtoQIzMqYYXBM4chGocoKdcmzRiGjgOYEtX3sC9owlmM5wn4dix+WvMlgFT+UHEU h313j7HX5LX5HM23pBHq+iu1OdGxhN/m2EHjjvcL1eSSBdv8mgsrT6kQSlpHMn2pfsYo PvWA== X-Received: by 10.194.95.100 with SMTP id dj4mr70774780wjb.48.1417216851382; Fri, 28 Nov 2014 15:20:51 -0800 (PST) Received: from [192.168.0.2] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id pu3sm16878651wjc.14.2014.11.28.15.20.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Nov 2014 15:20:50 -0800 (PST) Message-ID: <54790348.6010103@gmail.com> Date: Fri, 28 Nov 2014 23:20:40 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: internals@lists.php.net References: <5478E3CD.7030803@mabe.berlin> In-Reply-To: <5478E3CD.7030803@mabe.berlin> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] New function: spl_object_id() or spl_object_handle() From: rowan.collins@gmail.com (Rowan Collins) On 28/11/2014 21:06, Marc Bennewitz wrote: > But to have a unique ID for objects sound like a very good idea and > would solve the object as array key issue. > I'm sure it's not as simple as the function prototype explained in > this thread previously. Indeed. Fortunately, we already have one: it's called spl_object_hash() If the current limitation of handles being potentially reused (which would also affect this proposal) can be solved, then it can be done there without creating a new function, as far as I can see. For quick comparison, here's the key line of the proposed implementation: RETURN_LONG(Z_OBJ_HANDLE_P(obj)); And here's the key lines of the spl_object_hash() implementation [1]: SPL_G(hash_mask_handle) = (intptr_t)(php_mt_rand(TSRMLS_C) >> 1); SPL_G(hash_mask_handlers) = (intptr_t)(php_mt_rand(TSRMLS_C) >> 1); ... hash_handle = SPL_G(hash_mask_handle)^(intptr_t)Z_OBJ_HANDLE_P(obj); hash_handlers = SPL_G(hash_mask_handlers)^(intptr_t)Z_OBJ_HT_P(obj); return strpprintf(32, "%016lx%016lx", hash_handle, hash_handlers); So, the existing function varies based on the object's "handle" (the part the simple implementation would return unhashed), its "handlers", plus some per-thread randomness. [1] http://lxr.php.net/xref/PHP_TRUNK/ext/spl/php_spl.c#756 -- Rowan Collins [IMSoP]