Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78068 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96457 invoked from network); 14 Oct 2014 21:28:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Oct 2014 21:28:39 -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.174 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.174 mail-wi0-f174.google.com Received: from [209.85.212.174] ([209.85.212.174:63072] helo=mail-wi0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CE/67-18603-6859D345 for ; Tue, 14 Oct 2014 17:28:39 -0400 Received: by mail-wi0-f174.google.com with SMTP id h11so8021263wiw.1 for ; Tue, 14 Oct 2014 14:28:35 -0700 (PDT) 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=o0pm30PvkhliWSRaYewr0VFnmEJKb4BbW1Yb4/CyyGA=; b=X8xYzsRMZJ0cUpAibVwtxWNyPdCMQWBNybAyo8qUr7N/TFKzNyhmOZDPCezYuFCK0W ioIU7oMYJZdzDBBk8H4QmqTAl6yZPuVHhwyaMiyrYDyY1jar5/+9ZRLPjeTN8y+/RmQW vVIE6m83oeMlc71RnsEU1NrqtuEqKvEK0/O1kepfkAJTzpeVT4uFnsvG6kYO8TIzZkJY su7GfcE4FJMA9uLBD+7ICXNGkzWZRt/siWdpXDv7j7IlgMmM3c/96PJMjTp6hXqbhqAr rsHnI1n4E7DDhJ3qTuNIE4kCBg//FgPyoVEKGYZvv6Z5Sz7aPn+nzuWSxyp3BgC/3n5i zxwQ== X-Received: by 10.194.57.141 with SMTP id i13mr7422839wjq.19.1413322115837; Tue, 14 Oct 2014 14:28:35 -0700 (PDT) Received: from [192.168.0.2] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id d3sm17052336wix.5.2014.10.14.14.28.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 14 Oct 2014 14:28:35 -0700 (PDT) Message-ID: <543D9580.60202@gmail.com> Date: Tue, 14 Oct 2014 22:28:32 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: internals@lists.php.net References: <543C9E9F.80804@mabe.berlin> <543CCFEA.2080908@sugarcrm.com> <543D7D18.9010100@mabe.berlin> <543D8E87.9050606@sugarcrm.com> In-Reply-To: <543D8E87.9050606@sugarcrm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Possibilities to fix some really poor behaviors in PHP7 From: rowan.collins@gmail.com (Rowan Collins) On 14/10/2014 21:58, Stas Malyshev wrote: >> |$obj = (object)array('123' => '456'); >> var_dump($obj); > Here the array had numeric index, so the object property became numeric > index too. The alternative for this would be for this operation to scan > through whole array and convert each key from numeric to string, which > given how exotic is this case seems to be a waste of time. > >> For the case of object to array conversion a numeric check could be very >> improved by simply check if the first character between 0-9 before >> starting the complete numeric check. That would be very fest and it > You seem to ignore the fact that you still have to go through the whole > array and scan each key and convert some of them, and all this work in > 99.99999% of real cases is for nothing and is useful only in an invented > abstract example. So the question is - would this check be useful for > anything than fixing an exotic case which nobody ever encounters in > practice? I think you may be over-estimating the performance impact of this somewhat. For the array-to-object conversion, no scanning is necessary, since the internal implementation already knows which keys are integers and which strings. For the vast majority of cases, the array passed in will have no integer keys, so overhead is effectively zero; for an array containing numeric keys, the overhead will be the time taken to create a string property key for each integer array key. By your own argument, this situation is sufficiently rare that very few people will be affected. For the object-to-array conversion, there will be an additional overhead, which will be proportional to the number of properties on the object. I would strongly suspect that most objects have very few properties, and very few property names would pass a simple test of "is first character a digit" but subsequently fail the full is numeric test. So again, the major part of the overhead would only be felt by those rare people who encounter this issue. There is still complexity overhead here, obviously, so this doesn't completely nullify your point. -- Rowan Collins [IMSoP]