Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57009 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27691 invoked from network); 22 Dec 2011 18:41:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Dec 2011 18:41:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.160.170 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.160.170 mail-gy0-f170.google.com Received: from [209.85.160.170] ([209.85.160.170:61538] helo=mail-gy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B9/69-12618-CD973FE4 for ; Thu, 22 Dec 2011 13:41:33 -0500 Received: by ghrr1 with SMTP id r1so2876219ghr.29 for ; Thu, 22 Dec 2011 10:41:30 -0800 (PST) Received: by 10.50.45.170 with SMTP id o10mr10055712igm.12.1324579290341; Thu, 22 Dec 2011 10:41:30 -0800 (PST) Received: from [192.168.200.5] (c-50-131-44-225.hsd1.ca.comcast.net. [50.131.44.225]) by mx.google.com with ESMTPS id l28sm31709363ibc.3.2011.12.22.10.41.29 (version=SSLv3 cipher=OTHER); Thu, 22 Dec 2011 10:41:29 -0800 (PST) Message-ID: <4EF379D8.9000206@lerdorf.com> Date: Thu, 22 Dec 2011 10:41:28 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111124 Thunderbird/8.0 MIME-Version: 1.0 To: Keloran CC: Dmitri Snytkine , Alain Williams , internals@lists.php.net References: <2095305E-D4E3-4D7E-8218-32EE99688E0C@GMAIL.COM> <2C90FB94-38C4-4270-8C6A-B89304BA8ED8@gmail.com> <159A7CA2-8561-40DA-9434-CAAE12304DDB@gmail.com> <005701ccc0b3$58c8dee0$0a5a9ca0$@alliantinternet.com> <20111222145159.GY25857@alliantinternet.com> <006101ccc0ba$46b81160$d4283420$@alliantinternet.com> In-Reply-To: X-Enigmail-Version: 1.4a1pre Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Return Type Hinting for Methods RFC From: rasmus@lerdorf.com (Rasmus Lerdorf) On 12/22/2011 07:08 AM, Keloran wrote: > i would love to see this expanded aswell (the way type hinting on function > variables was supposed to be), so that it could be > > string, int > > e.g. > function int test(bool $tester) { > if ($tester) { return 5; } > return 99; > } Return type hinting needs to be aligned with parameter type hinting, and as has been pointed out many times on this list, type hinting for interchangable scalar types is a really bad idea. It will push all type checking up to the caller of the underlying functions/methods. PHP is primarily a Web scripting language and the Web isn't typed. Having stuff like this break: if(age_check($_POST['age'])) { do_stuff(); } because the author of the age_check() function added an int type hint just doesn't make any sense. It would cause everyone to have to start casting things everywhere, just in case. eg. if(age_check((int)$_POST['age'])) { do_stuff(); } This is not a step forward. If the author of age_check() really doesn't want to accept type-juggled arguments, then it is easy enough to do a strict type check in the function itself. This puts the effort in the correct place and doesn't encourage this type of coding. -Rasmus