Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89290 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24076 invoked from network); 22 Nov 2015 05:02:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Nov 2015 05:02:25 -0000 Authentication-Results: pb1.pair.com header.from=laruence@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=xinchen.h@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.213.43 as permitted sender) X-PHP-List-Original-Sender: xinchen.h@zend.com X-Host-Fingerprint: 209.85.213.43 mail-vk0-f43.google.com Received: from [209.85.213.43] ([209.85.213.43:33809] helo=mail-vk0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E4/A2-23339-D5C41565 for ; Sun, 22 Nov 2015 00:02:22 -0500 Received: by vkbs1 with SMTP id s1so20028261vkb.1 for ; Sat, 21 Nov 2015 21:02:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=SsST64WPzNw09wvQzR7/ZouHbRyI3xXOTMzHyngIo8I=; b=bpLrf8/qwJXns9S6p7oXciNdGammLzeo/4TB1fR6BYwabB/SYXe5nj1Vp7lSDvDJGN DYAOT+DlNEHmyaekf+0XbP7pLZZ3heeuUa6mQsn6Hs+RGqE7IVAZpbIjX9O1FSTKy53h alUN5Sl/w/VQ1y9yFdEo5XygjrynPUIDbf/CTG3W/1MEF5WDvWRbQGIIEcMg/ZTiBxoT 0b4axr09O49kG5zByKmBHdvrei4KPqGuwJQqI33LH5S00RriZj5QxjHyr0ckEPTJBuaa DJWQ2gBUNDI0CTA2lLCT9yURJpEE1Xz/+Z01b9s5Cbvu5zlBY+rQSH/ErZz5RFwb6t8Y zpiw== X-Gm-Message-State: ALoCoQk5qhAEgxf/Bb+X0eEN1MD+NGy8nJ9Jw0tFap/vma/MpPSKcTmrsq/As31ESHymQ9VzoLHvcpDT/D2Ywg/gK7N3DHjSIpoGch887EcFaZw1ruElWZgMPmcFgRzqO3b5anJkqOpDrMRwl3H0NBHFXTaT/S2Xownic7llJJjyYX/P4BS899k= X-Received: by 10.31.133.203 with SMTP id h194mr9979130vkd.32.1448168538850; Sat, 21 Nov 2015 21:02:18 -0800 (PST) Received: from mail-vk0-f54.google.com (mail-vk0-f54.google.com. [209.85.213.54]) by smtp.gmail.com with ESMTPSA id x128sm5865349vke.14.2015.11.21.21.02.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Nov 2015 21:02:18 -0800 (PST) Received: by vkfr145 with SMTP id r145so20128784vkf.0 for ; Sat, 21 Nov 2015 21:02:17 -0800 (PST) X-Received: by 10.31.180.87 with SMTP id d84mr9411503vkf.83.1448168537697; Sat, 21 Nov 2015 21:02:17 -0800 (PST) MIME-Version: 1.0 Received: by 10.31.229.7 with HTTP; Sat, 21 Nov 2015 21:01:58 -0800 (PST) In-Reply-To: References: Date: Sun, 22 Nov 2015 13:01:58 +0800 X-Gmail-Original-Message-ID: Message-ID: To: Anthony Ferrara Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a1143899643b74b05251a0317 Subject: Re: [PHP-DEV] INDRECT in arrays causes count() to become unpredictable From: laruence@php.net (Xinchen Hui) --001a1143899643b74b05251a0317 Content-Type: text/plain; charset=UTF-8 Hey: On Sun, Nov 22, 2015 at 6:47 AM, Anthony Ferrara wrote: > All, > > It appears that in our efforts to optimize PHP 7 we've introduced an > inconsistency into array handling. This is demonstrated by this > script: https://3v4l.org/hVcAB > > $a = 1; > unset($a); > var_dump(count($GLOBALS), $GLOBALS); > > The result is that the count doesn't match the contents of the array. > > It also affects objects casted to arrays in certain cases. > > Here, the array has 1 element, but should have 0. Trying to access the > "1" element "a" results in a notice. > > This means that the count is incorrect. This is due to the fact that > the "a" element follows an IS_INDIRECT type pointing to the other > symbol table. > > A potential solution would be to make count() an O(n) operation in the > case that the hashtable is a symbol table or if it has INDIRECT > elements. Meaning that we'd compute the real count at runtime. > > This obviously has performance ramifications, but we shouldn't > sacrifice consistency and behavior for performance IMHO. Especially > when it comes to core data structures. > > I think this is significant enough to be a blocker to gold and that we > should fix it prior to release. > I don't think so, it's only affects symbol tables. means, it won't affects normal arrays. like: 1, "bar" => 2, "dummy" => 3); unset($array["bar"]); var_dump(count($array)); ?> anyway, I've fixed this here: https://github.com/php/php-src/commit/eada2aa91add2de69bc5783b840a21243a7b0678 and, we maybe move this new functions into zend_hash(as a ZEND_API), anyway I am not sure whether it's okey for PHP-7.0. will discuss with welting and Dmitry on Monday. thanks > > Thoughts? > Anthony > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > -- Xinchen Hui @Laruence http://www.laruence.com/ --001a1143899643b74b05251a0317--