Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57046 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99786 invoked from network); 23 Dec 2011 00:29:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Dec 2011 00:29:40 -0000 Authentication-Results: pb1.pair.com smtp.mail=keisial@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=keisial@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.54 as permitted sender) X-PHP-List-Original-Sender: keisial@gmail.com X-Host-Fingerprint: 74.125.82.54 mail-ww0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:62600] helo=mail-ww0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2D/01-28504-47BC3FE4 for ; Thu, 22 Dec 2011 19:29:40 -0500 Received: by wgbdt13 with SMTP id dt13so15393695wgb.11 for ; Thu, 22 Dec 2011 16:29:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=p295pQS2h4cj6nm5npeaJmpWrM8AoOLBsw+c26FRc9w=; b=dGjcgkvASX7PZ6j4tBAdDN9fBAvoPb85gKby6GGzzpGMg8DG4ncKbp6RWIAm+v4RrM W3pxr0seZNdN+avoud2j0MIRwArTANtBQiPNTToCWnue+5LvoLJOEeAs08N4CF/oCGkq bk5z/lPvDhZ4aK/s+7GVeJgVm/uurSqrnoxoE= Received: by 10.227.200.204 with SMTP id ex12mr12350520wbb.7.1324600176848; Thu, 22 Dec 2011 16:29:36 -0800 (PST) Received: from [192.168.1.26] (51.Red-83-49-113.dynamicIP.rima-tde.net. [83.49.113.51]) by mx.google.com with ESMTPS id ei9sm26852072wid.0.2011.12.22.16.29.34 (version=SSLv3 cipher=OTHER); Thu, 22 Dec 2011 16:29:35 -0800 (PST) Message-ID: <4EF3CC69.3000103@gmail.com> Date: Fri, 23 Dec 2011 01:33:45 +0100 User-Agent: Thunderbird MIME-Version: 1.0 To: Will Fitch CC: Stas Malyshev , PHP Developers Mailing List References: <2095305E-D4E3-4D7E-8218-32EE99688E0C@GMAIL.COM> <2C90FB94-38C4-4270-8C6A-B89304BA8ED8@gmail.com> <159A7CA2-8561-40DA-9434-CAAE12304DDB@gmail.com> <4EF3B56A.4040809@gmail.com> <-2451498990672032588@unknownmsgid> <4EF3BD21.2040301@sugarcrm.com> <-6952580475866195972@unknownmsgid> In-Reply-To: <-6952580475866195972@unknownmsgid> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Return Type Hinting for Methods RFC From: keisial@gmail.com (=?UTF-8?B?w4FuZ2VsIEdvbnrDoWxleg==?=) On 23/12/11 01:00, Will Fitch wrote: > On Dec 22, 2011, at 6:28 PM, Stas Malyshev wrote: >> In PHP, returning object if everything is OK and false if not is a very common pattern. >> Also, you understand that always allowing null means that this construct: >> >> $foo = $this->returnsFoo(); >> $foo->fooMethod(); >> >> is no longer safe as you wanted it to be when you made returnsFoo use strict typing? You'd have to check $foo anyway. > Are you suggesting not allowing null to be returned, or provide an > indicator within the syntax that it may return null? It should be possible to allow it. Either with a generic syntax for allowing many types of return types or through a specific one (eg. in C# a ? marks an internal type as nullable: int? ) > PHP would be the > first language I'm aware of that would do so in either case. It already barfs at you if you pass null to a parameter expecting a given class (though you can allow it). > The point isn't to restrict a type hint to always be returned. The > goal is to guarantee that if a value is returned, it will be of type > X. In the event it is inappropriate to return the value back, would > you rather receive null or a bogus class instance, empty array or a > random function name back? Because that's what will happen. It will > become the "workaround" for not being able to return null. As it would support both ways, it's up to the framework to choose if they want to return null or a fake-class interface.