Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79277 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45148 invoked from network); 28 Nov 2014 14:03:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Nov 2014 14:03:06 -0000 Authentication-Results: pb1.pair.com header.from=php@bof.de; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=php@bof.de; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain bof.de designates 80.242.145.70 as permitted sender) X-PHP-List-Original-Sender: php@bof.de X-Host-Fingerprint: 80.242.145.70 mars.intermailgate.com Received: from [80.242.145.70] ([80.242.145.70:48113] helo=mars.intermailgate.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 15/AD-59154-69088745 for ; Fri, 28 Nov 2014 09:03:04 -0500 Received: (qmail 11639 invoked by uid 1009); 28 Nov 2014 15:02:59 +0100 Received: from 213.135.15.139 by mars (envelope-from , uid 89) with qmail-scanner-1.25-st-qms (clamdscan: 0.96.2/19690. spamassassin: 3.3.1. perlscan: 1.25-st-qms. Clear:RC:0(213.135.15.139):SA:0(1.6/10.0):. Processed in 1.19158 secs); 28 Nov 2014 14:02:59 -0000 X-Spam-Status: No, hits=1.6 required=10.0 X-Spam-Level: + X-Antivirus-MYDOMAIN-Mail-From: php@bof.de via mars X-Antivirus-MYDOMAIN: 1.25-st-qms (Clear:RC:0(213.135.15.139):SA:0(1.6/10.0):. Processed in 1.19158 secs Process 11627) Received: from unknown (HELO rofl.localnet) (gmail@bof.de@213.135.15.139) by mars.intermailgate.com with AES256-SHA encrypted SMTP; 28 Nov 2014 15:02:58 +0100 To: internals@lists.php.net Cc: Ferenc Kovacs , Sebastian Krebs , Bostjan Skufca Date: Fri, 28 Nov 2014 15:02:57 +0100 Message-ID: <9846323.EvUROnfLfe@rofl> User-Agent: KMail/4.11.5 (Linux/3.11.10-21-desktop; KDE/4.11.5; x86_64; ; ) In-Reply-To: References: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="nextPart3255192.mAnjtYO6B0" Content-Transfer-Encoding: 7Bit Subject: Re: [PHP-DEV] New function: spl_object_id() or spl_object_handle() From: php@bof.de (Patrick Schaaf) --nextPart3255192.mAnjtYO6B0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" On Friday 28 November 2014 14:51:55 Ferenc Kovacs wrote: > > I also used spl_object_hash() in the past when traversing/custom > serializing object structures which can have infinite recursions between > objects, but even that could be simply solved by storing the already > traversed objects in an array (as assigning the objects into another > variable doesn't have much overhead) and checking with in_array. Checking with in_array is O(N) while an array keyed on spl_object_hash() with the values being the objects, is stable wrt. hash string vs. object lifetime, and is O(1) on checking for key existence. The performance difference will become apparent when you have more than a handful of objects there. BTW, the two or three places where I use spl_object_hash(), in this way, are exactly your use case: as an "already visited" cache during traversal of somewhat arbitrary input structure (logging / dumping). best regards Patrick --nextPart3255192.mAnjtYO6B0--