Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57043 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95055 invoked from network); 23 Dec 2011 00:01:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Dec 2011 00:01:01 -0000 Authentication-Results: pb1.pair.com header.from=will.fitch@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=will.fitch@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.170 as permitted sender) X-PHP-List-Original-Sender: will.fitch@gmail.com X-Host-Fingerprint: 209.85.215.170 mail-ey0-f170.google.com Received: from [209.85.215.170] ([209.85.215.170:34426] helo=mail-ey0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 90/10-28504-BB4C3FE4 for ; Thu, 22 Dec 2011 19:01:00 -0500 Received: by eaai11 with SMTP id i11so8205583eaa.29 for ; Thu, 22 Dec 2011 16:00:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=references:from:in-reply-to:mime-version:date:message-id:subject:to :cc:content-type; bh=wtgIwe6Yz/SYcdm94jzXPn1swZfiKIMIkkkWIWItlFM=; b=XJyTxOW5zxWGUl0hoesRubLEbwEWtuZpxzwPtU8MOV0NXYSDLcpyblV323hahJhSOD fx/aSpGT7GQHWaUHm7/vsjoQA2OinaqiDbgokGR0YWATvMgk/AfO/L17fESyUHeQ06qM jMjY6sdgxqclHIqdXYO48IZW9GgXHbflybNbI= Received: by 10.204.131.74 with SMTP id w10mr3853897bks.36.1324598455647; Thu, 22 Dec 2011 16:00:55 -0800 (PST) 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> In-Reply-To: <4EF3BD21.2040301@sugarcrm.com> Mime-Version: 1.0 (1.0) Date: Thu, 22 Dec 2011 19:00:52 -0500 Message-ID: <-6952580475866195972@unknownmsgid> To: Stas Malyshev Cc: =?UTF-8?B?w4FuZ2VsIEdvbnrDoWxleg==?= , PHP Developers Mailing List Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Return Type Hinting for Methods RFC From: will.fitch@gmail.com (Will Fitch) On Dec 22, 2011, at 6:28 PM, Stas Malyshev wrote: > Hi! > >> Most modern languages allow returning null in any case. This is a hail >> Mary in the event something happens, but throwing an exception is >> inappropriate. I see no reason to diverge from that. > > 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? PHP would be the first language I'm aware of that would do so in either case. 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. > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227