Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87569 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19800 invoked from network); 3 Aug 2015 11:16:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Aug 2015 11:16:22 -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 209.85.212.178 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.178 mail-wi0-f178.google.com Received: from [209.85.212.178] ([209.85.212.178:34976] helo=mail-wi0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3E/31-13081-68D4FB55 for ; Mon, 03 Aug 2015 07:16:22 -0400 Received: by wibxm9 with SMTP id xm9so116458965wib.0 for ; Mon, 03 Aug 2015 04:16:19 -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:to:cc :message-id; bh=mBxM7spi2SekV3ps3i6lUln5WOIMRnEL12x3aEBJ3E4=; b=JjI+f70pbcRMwhVQfKJAnVmATao2c3NPI8cXHAzBm/1mJ2BFBULUxYhON2ypnL+eTp ir8tSufHtT3TlOmJ0sbMO2GQ88HLzTVcdeKEg4yAaeHp3vZeFZjPCIpgpxv4oB6vI5v1 DMVWI/+D0+NDQNSm0AWbxQwq563MzSmYPYeU8ARqQ2yVnUgyUlJnHZDDRnKlVRuQquNI FyZgS9wZOOyB6n/+prBI+5mtvkq/Mydw70JBfxPHDYUi05P8uATcB88xDc4Q+n9QT+MR wkIRM4vohJDvNESc0/wqySHC3t1EKv0QUHd0ldnurh+6ZLRO7MAWpkDXd5lxIErt+QVB kuzw== X-Received: by 10.180.231.40 with SMTP id td8mr33157640wic.9.1438600579536; Mon, 03 Aug 2015 04:16:19 -0700 (PDT) Received: from [100.75.218.196] ([213.205.194.252]) by smtp.gmail.com with ESMTPSA id c3sm22396300wja.3.2015.08.03.04.16.17 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Aug 2015 04:16:18 -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> <4557ED13-5446-45F1-8E04-A01F8A066600@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Mon, 03 Aug 2015 12:16:08 +0100 To: Nicolas Grekas CC: "internals@lists.php.net" Message-ID: Subject: Re: [PHP-DEV] Exposing object handles to userland From: rowan.collins@gmail.com (Rowan Collins) On 3 August 2015 11:52:06 BST, Nicolas Grekas wrote: >> 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]; >> } >> > > >Yep, that would work, but with the following drawbacks: >- it would create a memory leak/overhead If you're dumping so many objects that the array would grow to noticeable size, you're likely to have bigger problems actually using the output. There's probably more data in an optimised autoloader classmap than most people will generate with a function like this. >- more importantly for users, these ids couldn't be compared to >var_dumps'. Why do you need to compare the output of two dump functions? Just add a note to the documentation that these are not the same IDs. Regards, -- Rowan Collins [IMSoP]