Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89313 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20099 invoked from network); 23 Nov 2015 08:48:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Nov 2015 08:48:09 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.213.172 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.213.172 mail-ig0-f172.google.com Received: from [209.85.213.172] ([209.85.213.172:36684] helo=mail-ig0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A7/F2-01565-6C2D2565 for ; Mon, 23 Nov 2015 03:48:08 -0500 Received: by igcph11 with SMTP id ph11so46758187igc.1 for ; Mon, 23 Nov 2015 00:48:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zend-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ZH1x/ynC+iLmLH9k+hwvpMlUf9Dl1TQft6vtlflpqHw=; b=N9lD6W+0iT8enWdKIFsil5njMuZ0SlTdUER49IrxQjCY0yavSLu0K+oq7O8e26lvCz o9ZJQCxiTy/v7h1SK+Ndc56P54gy4Ez7Tnil52SHecqXSfp+Yw64v2YW/aXNjGh7j5VA 3j0ed/fVneMvLJEwfJctZruD+WLfOmixNq+FKZC2BWKI0WOWB3BS8MCJAZFtcO4ay444 +2SoP8YVThqSs9UOCdxg2dIbCwyPk/EG1mJ+HhZdFl/oElAQYVjIQsSULQDwf3KflBp5 XInTC3gE1Gd9voSnGacITPh6Wxi+v4YF39GtYdFlfZCLmGcsYjianwt+Ibz61xuOuqQr muoA== 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:date :message-id:subject:from:to:cc:content-type; bh=ZH1x/ynC+iLmLH9k+hwvpMlUf9Dl1TQft6vtlflpqHw=; b=gyYnY/Fkq7Nb55bRe8RJAVYdlmMQpVw14iq6ScG/9LHmBrJmw+ZrGNIl5HCssFv4UM mba/26EVhUnjVHPgPlSZKVAfDhMyNsKjtsNXgAsACUdMORwWiRPep7L5nkFOOiTI/TQn 0X4l6sQ+nOWbElrmwQPPV1odLHcmk028amGIZrVfGhlEonqzpd5eFwN21s7jPZtApNrz juN/MrtBwOQYK7IoMsB5+oHfoXbzbgLF5rXmFKum1GR8aJ88BHA42EqQA8xkoB6MoEMx bbDq65rzQtdRBYDGMMfIze8lkMVS9ZDN2c3RVuihUQUChRK6FZyQS4n5AfPiZuTGP2nF OOPg== X-Gm-Message-State: ALoCoQkiqpCz2eIZRue3cVpE3FJ3StZEUlnELm5kQ4X1I9mh5fhFZ5nW6Q3AnF1jtGpCaN4XXfAKMx4YdN25AtcFf+0Ywu/9aV/dsTYsagBRbTOQ+W8IcrTQ0pDslBbBuJ2ES2k0vdz8jn3vxlJDII64nDgZHMmDpLJSfB2DdLaU0fTfRStmehQ= MIME-Version: 1.0 X-Received: by 10.50.176.166 with SMTP id cj6mr10829734igc.74.1448268483794; Mon, 23 Nov 2015 00:48:03 -0800 (PST) Received: by 10.50.128.201 with HTTP; Mon, 23 Nov 2015 00:48:03 -0800 (PST) In-Reply-To: References: Date: Mon, 23 Nov 2015 11:48:03 +0300 Message-ID: To: Xinchen Hui Cc: Anthony Ferrara , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=e89a8f6435a28442bb05253148a6 Subject: Re: [PHP-DEV] INDRECT in arrays causes count() to become unpredictable From: dmitry@zend.com (Dmitry Stogov) --e89a8f6435a28442bb05253148a6 Content-Type: text/plain; charset=UTF-8 On Sun, Nov 22, 2015 at 8:01 AM, Xinchen Hui wrote: > 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: > > > $array = range(1, 10); > unset($array[2]); > var_dump(count($array)); > > > $array = array("foo" => 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. > The patch looks fine. We already use something similar for serialise(). Thanks. Dmitry. > > 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/ > --e89a8f6435a28442bb05253148a6--