Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79493 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70633 invoked from network); 9 Dec 2014 11:18:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Dec 2014 11:18:45 -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.172 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.172 mail-wi0-f172.google.com Received: from [209.85.212.172] ([209.85.212.172:34590] helo=mail-wi0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 69/63-39368-39AD6845 for ; Tue, 09 Dec 2014 06:18:44 -0500 Received: by mail-wi0-f172.google.com with SMTP id n3so7493751wiv.17 for ; Tue, 09 Dec 2014 03:18:40 -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=DxQKjuQm5gW6FtMZL3IsV1HfUU+MM/yAxQHNQuZPB+Y=; b=syxED2m3QuyvxzmZ3To0Ia+KJaTbWlfyPcz7pvkR3eCTAwrxIiHaqYmfFuF7Lxhty2 VJWUMycCkUFuLukT/uxpC3Il3nEQ07nOlR4IV+ZFjcd03hpX4x9oAQshIuUazsrV8EqB ikR0SHo5Ub4RPHEoFUBJ0j2TBb29NeKEzYhix2r1F2ZJW5r9lEE+xinaIITvAUcmjFS0 l82sM4Gikj+hwfjPH952PFRTgSqGouC55kxsouPdQx3ZpHCGSMbbaz9KEGkYO+uCrAKD aH/R0vJg6Mgmykpl1DbDnzMxM5oNqOf1qPYmQTqobgvureTZ5+sCoN3XsTU3wE5XThYX DrOQ== X-Received: by 10.194.122.66 with SMTP id lq2mr4022271wjb.54.1418123920128; Tue, 09 Dec 2014 03:18:40 -0800 (PST) Received: from [192.168.0.148] ([62.189.198.114]) by mx.google.com with ESMTPSA id h14sm1806783wic.8.2014.12.09.03.18.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Dec 2014 03:18:39 -0800 (PST) Message-ID: <5486DA89.3090605@gmail.com> Date: Tue, 09 Dec 2014 11:18:33 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: 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) Nicolas Grekas wrote on 09/12/2014 09:31: > Hi > > > this is a proposal to add new function to PHP core: spl_object_id() > IMHO this is a good idea: currently, var_dump has this super-power (and > super-useful) capability of outputting a number that ease recognizing > identical objects in dumps. This power should be transferred to userland > devs so they can build their own tools. > > In fact, that's what I've done: since Symfony 2.6, you can dump using a > userland function that (IMHO again) is more powerful than var_dump: > > http://symfony.com/doc/current/components/var_dumper/introduction.html > > In order to get an object's id, I use a trick that works for now: > https://github.com/symfony/symfony/blob/2.6/src/Symfony/Component/VarDumper/Cloner/VarCloner.php#L258-L282 This seems like a very elaborate piece of reverse engineering for very little gain. If you just want to turn the result of spl_object_hash into a consistent integer, just use whatever re-hashing you like. The exact value of the "object handle" is not something you could ever do anything with anyway, surely? > But I'd prefer replacing this trick by a dedicated function. So, with > Julien Pauli, we worked on such a function. Symfony 2.6 also embeds a PHP > extension that exposes more meta data about variables: > https://github.com/symfony/symfony/tree/2.6/src/Symfony/Component/Debug/Resources/ext > > The function implemented in this extension is the root primitive that > enables building a feature-full dumper, without resorting to tricks in PHP. The more interesting part of this is the refcount - unlike spl_object_hash(), which does its job just fine, debug_zval_dump() *is* broken, because the documented use requires call-time pass-by-reference, which is actually impossible in current versions of PHP. A replacement would presumably need to hook in as a language construct rather than a function, so that the function call itself doesn't mess up the refcount and is_ref status of a ZVAL? Regards, -- Rowan Collins [IMSoP]