Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57020 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46316 invoked from network); 22 Dec 2011 19:21:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Dec 2011 19:21:04 -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:49117] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/AD-12618-F1383FE4 for ; Thu, 22 Dec 2011 14:21:04 -0500 Received: by qcsd16 with SMTP id d16so5557597qcs.29 for ; Thu, 22 Dec 2011 11:21:01 -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=adX4upFBwdO0GbpJXUFOp+hhUvIVzNzneGB7dLAtHPg=; b=TXINCUpX/LrlmF74l27k9DkVulM9bw7pzTpTyKL1l/eV7lNagovO8NnNVXdy7uTSoj mHL7WhaJpAANV5oaPvH6JVLAJbrlREe1RETvxxbsIx5j0EvDZFWiRJyzq87RL81niWSA qpzVCsbcslat+HsGDKt0+7l21qyA6iM6vGBR0= Received: by 10.224.197.202 with SMTP id el10mr15688202qab.39.1324581661029; Thu, 22 Dec 2011 11:21:01 -0800 (PST) Received: from [192.168.1.68] ([68.64.144.221]) by mx.google.com with ESMTPS id m20sm18995956qaj.14.2011.12.22.11.20.59 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 22 Dec 2011 11:21:00 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1251.1) Content-Type: text/plain; charset=iso-8859-1 In-Reply-To: Date: Thu, 22 Dec 2011 14:20:58 -0500 Cc: Rasmus Lerdorf , Keloran , Dmitri Snytkine , Alain Williams , internals@lists.php.net 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> <005701ccc0b3$58c8dee0$0a5a9ca0$@alliantinternet.com> <20111222145159.GY25857@alliantinternet.com> <006101ccc0ba$46b81160$d4283420$@alliantinternet.com> <4EF379D8.9000206@lerdorf.com> To: Paul Dragoonis 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 1:50 PM, Paul Dragoonis wrote: > On Thu, Dec 22, 2011 at 6:41 PM, Rasmus Lerdorf = wrote: >=20 >> 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 >>>=20 >>> string, int >>>=20 >>> e.g. >>> function int test(bool $tester) { >>> if ($tester) { return 5; } >>> return 99; >>> } >>=20 >> 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: >>=20 >> if(age_check($_POST['age'])) { do_stuff(); } >>=20 >> 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. >>=20 >> if(age_check((int)$_POST['age'])) { do_stuff(); } >>=20 >> 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. >>=20 >=20 > I agree with Rasmus. >=20 > My opinion: > This isn't java, if you want a strongly typed language, there's plenty = out > there, but we're not looking to make PHP more like Java and the rest, = if it > was like Java then it wouldn't have been successful for the web as it > is/was. PHP is popular because of the way it was from the start, if = php > _needed_ scalar typehints then it wouldn't have been as popular. >=20 > There is need for the existing Typehinting for class types so you = don't > need to have is_a() function calls. This makes sense. >=20 > Scalars are VERY powerful in PHP, because of its loose typed nature. = Having > a 'numeric' typehint makes sense, because it can be an int, float, or > string. Adding typehints like 'int' and 'float' will only piss people = off, > and make PHP more difficult and less fluent to code in. >=20 > Lets not go there please.. I agree. Let's not go there. I'd like to focus more on the actual RFC = at hand. It makes sense to discuss potentials and what if's, but type = hinting scalars has been shot down many times - the most important being = that it would destroy the loosely typed nature of scalars. >=20 > Thanks, > Paul Dragoonis. >=20 >=20 >=20 >>=20 >> -Rasmus >>=20 >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >>=20 >>=20