Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103080 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4041 invoked from network); 11 Aug 2018 13:34:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Aug 2018 13:34:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.15.18 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.15.18 mout.gmx.net Received: from [212.227.15.18] ([212.227.15.18:60933] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CE/70-32660-4F5EE6B5 for ; Sat, 11 Aug 2018 09:34:44 -0400 Received: from [192.168.2.102] ([87.167.201.185]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MC4R6-1ffeKm37o0-008sbv; Sat, 11 Aug 2018 15:34:40 +0200 To: Sara Golemon , PHP internals References: Message-ID: <03a9b282-1a46-c2a6-6987-0f2778f99be4@gmx.de> Date: Sat, 11 Aug 2018 15:34:42 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:23vvVowEkOvpU2y7qHSwUXI6aun8gPI906VGTdKxcxJokpi6iwj dmyyekGyaAnw02MkDkGfKoazltg3igKXBWCT7n7AlshJRk0v0KI90bWClgy8uHJkBoObc4r 5+PfDu2RKpnW0eVJsUC48amQXvSoD6s44jf5nHQDhcvexYksp8l+kNZGxtlLv1H1EammkqS 4u6+M9hqnlxSyHqKBO2wQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:/GAdwMtmqco=:TCt/NTm5drOCSWHyOSOYec 11bAuAmXzix4o9ntfGf17Wef2hUoMtcd4lH/aScXqgEewOa23HawgzGq6z51XtFbwGb2ilHz6 WiTra+U/ko1ij0q65Jn778zyfQkjqvb2+kKBZTiB/7iGz+v/9MLWHqq6Bh2zi9q40UsGQcCKW VeHlqbNUdw1fyVZJ7OOFT5Amlm7UQ2qFsNSjKBeAc7Czu1ICOO7sh2eZDF83+26a2iEImKJE6 jALqwsGj2gUvcPU3TesHQ3aVaxs71RwFUKa6qK+xYGpG23hvXDdKTJpDMcv/2l7TD0bjBdz5x /YykuPVG3WHSsRYTKGHP07YEcJ/Z7AjPEFeDGgVVJowI+46Dhdk2xE4o8ILt8d1MPp4BHCt4s QmiJ8cDhjTnAYELiJ7XIyiDX1VgLF4T+bV/Xdp5ykP5IW15Xa8X5LxDwzzBMyy40nbN/T/vvu RnnTAiKhcWvphCLgt9FWW3JJfYRxlVlzFamAZ4qkz/Tpo9q6ODb1rHPurihsftyhAn7f0RuG8 wP5Jm+dMAT0no9Uppe2ph18QcFxrzxvy5o5m6cTA7TjCOc2jKAcr8OddXY6/aKKvQHt9xddMu dpRWUMl89xXpLqJ1qNyKwVQM460L3xsjQMGTxQj9sy13WFPe3UbwX61rog9QXN2tVA9Xn8SJ9 0Jr++ocomhh+W04PccFaUT2Yo/NpyOsGHu9MjYRD3P2JWf00Il09YHAiXY1kqzEysXVCR12GZ j+dP4K83qD0jpSlA74IvO/CiNkLogqQGvn366dtT/t2uEg99xQPEnGux3gGeZZ10BlTATLXvi t0SmFGQ Subject: Re: The curious case of the comparable objects. From: cmbecker69@gmx.de ("Christoph M. Becker") On 10.08.2018 at 17:12, Sara Golemon wrote: > One of the contributors for the "Because, PHP" page came up with a fun > example where the result of object comparison changes upon observation > of that object. > > class A { public $a; } > class B extends A { public $b; } > $a = new B(); $a->a = 0; $a->b = 1; > $b = new B(); $b->a = 1; $b->b = 0; > > var_dump($a < $b); // bool(true) > print_r($a); // Output is unimportant > var_dump($a < $b); // bool(false) > > Tracked this down to the introduction of slotted object properties > introduced in PHP 5.4 and some optimistic logic contained in > zend_object_handlers.c. > > TL;DR - The print_r is materializing the ->properties HashTable in the > first object. Once that happens, zend_std_compare_objects() flips > from walking the slotted properties in properties_table to > materializing both ->propoperties HashTables and using a symtable > compare. The result differs, because rebuild_object_properties walks > ->properties_info which may not necessarily be in the same order as > the values ->properties_table. > > See also my writeup here: https://3v4l.org/NLZNm > > So the questions for us are: > > 1. Does this matter? (I think so, it's spooky action at a distance) ACK. > 2. Is it a bug introduced in 5.4 that's okay to fix? Or would fixing > it count as a BC break due to how long it's been broken? (I say > fixable bug, the BC break was at 5.4) I tend to agree, even though the behavior is not really documented. The php.net manual says nothing about the ordering of objects, and the language specification isn't clear about that, since it refers to array comparison[1], but doesn't define the order of the properties. Are properties of parent classes inserted before the properties of child classes? Are ad-hoc properties inserted after the predefined ones? Are trait properties inserted where the are “use”d? Are invisible properties also part of the comparison? > 3. If yes to 1&2, how far back do we fix it? Bugfix branches (7.1+)? > Or would a change like this in branch be too much? Surely at least 7.3 > could be fixed. Fixing this for 7.3 is certainly okay; I'm not sure about former versions. [1] -- Christoph M. Becker