Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71172 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94979 invoked from network); 16 Jan 2014 10:01:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jan 2014 10:01:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: php@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:34237] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B7/A0-24763-AFDA7D25 for ; Thu, 16 Jan 2014 05:01:32 -0500 Received: (qmail 32076 invoked by uid 48); 16 Jan 2014 11:01:28 +0100 Received: from 193.170.124.203 ([193.170.124.203]) by webmail.tutteli.ch (Horde Framework) with HTTP; Thu, 16 Jan 2014 11:01:27 +0100 Message-ID: <20140116110127.202079vzjsj76n7b@webmail.tutteli.ch> Date: Thu, 16 Jan 2014 11:01:27 +0100 To: Martin Keckeis Cc: Andrea Faulds , Crypto Compress , PHP internals References: <001301cf1227$6d082ab0$47188010$@tutteli.ch> <002d01cf1234$01e6dc60$05b49520$@tutteli.ch> <004c01cf123d$35730870$a0591950$@tutteli.ch> <52D71748.1090402@googlemail.com> <52D71FAE.8030002@ajf.me> <005001cf124f$3a40df00$aec29d00$@tutteli.ch> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; DelSp="Yes"; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: 7bit User-Agent: Internet Messaging Program (IMP) H3 (4.3.6) Subject: Re: [PHP-DEV] Introducing "Array Of" RFC From: php@tutteli.ch > + 1 for the RFC > > But if i'm not completely wrong, there is performance decrease instead of > increase in your tests? > https://gist.github.com/krakjoe/8444591 > > [joe@fiji php-src]$ sapi/cli/php isTest.php 10000 > objects: 10000 > arrayof: 0.00645113 > instanceof: 0.00560713 I gave the RFC a few more thoughts and came to the conclusion that it does not fit to PHP (due to the performance penalties involved). The syntax merely hide an ugly design. If you would write the same in normal PHP then probably everyone would agree that it is bad design. Following an example (doesn't really make sense but outlines the bad design) function foo(Foo[] $foos){ if(count($foos) > 0){ $a = array_pop($foos); //do something foo($foos); } } Is equivalent to function foo(array $arr){ foreach($arr as $v){ if(!($v instanceof Foo)){ //trigger_error } } if(count($foos) > 0){ $a = array_pop($foos); //do something foo($foos); } } The check adds runtime complexity to the function for each call which is obviously not necessary (once would be good enough). And I doubt that users would actually make sure that the check is only performed once and even if you would argue that one should write it as follows: function bar(Foo[] $foos){ foo($foos); } function foo(array $foos){ if(count($foos) > 0){ $a = array_pop($foos); //do something foo($foos); } } Then it is still bad design compared to a collection which actually does the check during the addition of elements. Although, I like the effort to make PHP somewhat more type safe I am -1 for this RFC, the implementation respectively. If we want typed arrays then the array needs to carry the type to be efficient.