Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57053 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13819 invoked from network); 23 Dec 2011 01:53:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Dec 2011 01:53:31 -0000 Authentication-Results: pb1.pair.com smtp.mail=will.fitch@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=will.fitch@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.170 as permitted sender) X-PHP-List-Original-Sender: will.fitch@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qy0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:61640] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 61/A3-28504-A1FD3FE4 for ; Thu, 22 Dec 2011 20:53:31 -0500 Received: by qcsd16 with SMTP id d16so5713133qcs.29 for ; Thu, 22 Dec 2011 17:53:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; bh=OvI8J3Z8kYe5F7XlYNvBoojVhmbCjp6+5DMnYvvrJnE=; b=xbkyKLWzeKBZCZIMWPR5ZWc42WXDYOEdqgYgjjvxWTG7PqglP69yw721SBAPgXcWlI 65aib7ARlvMThyhUP8Gze1b6pU4JNDkGDpj1YsQhpVVW0Og1kb+/ohCPhOzRUVvfj7d0 PL0zDkvMDVJsstPNSwOnw5iwTd77MhLHGz/2E= Received: by 10.224.187.20 with SMTP id cu20mr16326670qab.43.1324605207567; Thu, 22 Dec 2011 17:53:27 -0800 (PST) Received: from [10.0.0.10] (c-71-225-170-108.hsd1.pa.comcast.net. [71.225.170.108]) by mx.google.com with ESMTPS id dm3sm20885573qab.12.2011.12.22.17.53.26 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 22 Dec 2011 17:53:26 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1251.1) Content-Type: text/plain; charset=iso-8859-1 In-Reply-To: <4EF3CC69.3000103@gmail.com> Date: Thu, 22 Dec 2011 20:53:24 -0500 Cc: Stas Malyshev , PHP Developers Mailing List Content-Transfer-Encoding: quoted-printable Message-ID: 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> <4EF3CC69.3000103@gmail.com> To: =?iso-8859-1?Q?=C1ngel_Gonz=E1lez?= X-Mailer: Apple Mail (2.1251.1) Subject: Re: [PHP-DEV] Return Type Hinting for Methods RFC From: will.fitch@gmail.com (Will Fitch) On Dec 22, 2011, at 7:33 PM, =C1ngel Gonz=E1lez wrote: > 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: >>>=20 >>> $foo =3D $this->returnsFoo(); >>> $foo->fooMethod(); >>>=20 >>> 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?=20 > 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? ) You can return null from methods. Parameters and variables are = nullable. I'm not against appending an indicator as to whether null may = be returned, but that would need to be a general consensus, I think. I would like other opinions on this... >=20 >> 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). >=20 >=20 >> 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. Yes, it would. But providing the option of null would be a good = incentive not to do that. At the end of the day, you're giving a set of = tools to someone. If they choose to use it in a way that's less = efficient, or wrong in other's eyes, that's their choice. >=20 >=20