Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71174 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98701 invoked from network); 16 Jan 2014 10:38:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jan 2014 10:38:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=hello@apfelbox.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=hello@apfelbox.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain apfelbox.net from 37.139.17.48 cause and error) X-PHP-List-Original-Sender: hello@apfelbox.net X-Host-Fingerprint: 37.139.17.48 mail.apfelbox.net Received: from [37.139.17.48] ([37.139.17.48:43587] helo=mail.apfelbox.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 72/61-24763-3B6B7D25 for ; Thu, 16 Jan 2014 05:38:44 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.apfelbox.net (Postfix) with ESMTP id E6805121E8E; Thu, 16 Jan 2014 10:38:39 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at mail.apfelbox.net Received: from mail.apfelbox.net ([127.0.0.1]) by localhost (mail.apfelbox.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Wyf35drKUXvJ; Thu, 16 Jan 2014 10:38:38 +0000 (UTC) Date: Thu, 16 Jan 2014 11:38:35 +0100 To: Robert Stoll Cc: 'Philip Sturgeon' , 'Marco Pivetta' , 'Kristopher' , internals@lists.php.net Message-ID: <29D5E17DED4340E4AB756A336E0D3E80@apfelbox.net> In-Reply-To: <004c01cf123d$35730870$a0591950$@tutteli.ch> References: <001301cf1227$6d082ab0$47188010$@tutteli.ch> <002d01cf1234$01e6dc60$05b49520$@tutteli.ch> <004c01cf123d$35730870$a0591950$@tutteli.ch> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="52d7b6ab_140e0f76_e1d" Subject: Re: [PHP-DEV] Introducing "Array Of" RFC From: hello@apfelbox.net (Jannik Zschiesche) --52d7b6ab_140e0f76_e1d Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, Am Mittwoch, 15. Januar 2014 um 23:00 schrieb Robert Stoll: > Fair enough, the example with the English sentence makes pretty much sense from an average user's point of view and thus > most PHP users would probably agree with you (don't take it wrong, I don't imply you are average or something similar). > However, this should not be a decision based on whether many people are preferring it this way or the other way round in > my opinion, since the restriction is going to make it impossible to use it for the use cases where NULL is a valid > entry. > So, we should ask ourselves, do we really want to exclude a whole bunch of valid use cases or should we decline the > restriction and put more effort in providing alternatives for non-null -containing collections. > > See, if we do not introduce the restriction and provide a non-null-containing collection then all use cases can be > supported. That is the way to go IMO. > Or do you have another idea how one can specify that the array can contain null? > And please consider, if you should suggest "function foo(Foo[] $foo=null)" implies that $foo can also contain NULL then > we have another vague concept in PHP which has a double meaning -> $foo can be NULL and entries in $foo can be NULL. But > maybe one does not want to allow NULL for $foo but only for members of $foo. > > if you pass an array which mixes both objects and null and you want to work on the objects, you still have to do the checks yourself: function f (A[] $list) { foreach ($list as $entry) { if (!is_null($entry)) { $entry->doSth(); } } } But in this case you could just omit the type hint and check it internally: function f ($list) { foreach ($list as $entry) { if (!is_null($entry) && ($entry instanceof A)) { $entry->doSth(); } } } The thought of this proposal is that the complete checking is done with just the type hint. And allowing null would make this obsolete. Also, you would then have the duplicated runtime impact: you need to check the array twice: 1. check for null & A (type hint) 2. check for A instead of just one. Cheers Jannik --52d7b6ab_140e0f76_e1d--