Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57010 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33726 invoked from network); 22 Dec 2011 18:50:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Dec 2011 18:50:57 -0000 Authentication-Results: pb1.pair.com smtp.mail=dragoonis@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dragoonis@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.49 as permitted sender) X-PHP-List-Original-Sender: dragoonis@gmail.com X-Host-Fingerprint: 209.85.216.49 mail-qw0-f49.google.com Received: from [209.85.216.49] ([209.85.216.49:38574] helo=mail-qw0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3E/CA-12618-01C73FE4 for ; Thu, 22 Dec 2011 13:50:56 -0500 Received: by qadc14 with SMTP id c14so5935543qad.8 for ; Thu, 22 Dec 2011 10:50:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=krOjjhFSSBH/JoBFv6At/e9MI4IhT26eGRDPMl1UPpc=; b=fXVy5alEU2VxHQ2Tr/uwsWn/0bGDI4YEpTK/akAtWXcjrv6JFxC3fnCMmBG027AAgw 68lZUL67ANwWsVI9IMrHXFfN4Fr9+KU7eq7i3y2t8jFvAiV/HwUYv1moxz07snizryB8 lJdX9csH3BAUX9gBb6d39bE73xN29Fdj5Mno0= MIME-Version: 1.0 Received: by 10.224.39.81 with SMTP id f17mr15192494qae.63.1324579853981; Thu, 22 Dec 2011 10:50:53 -0800 (PST) Received: by 10.229.39.72 with HTTP; Thu, 22 Dec 2011 10:50:53 -0800 (PST) In-Reply-To: <4EF379D8.9000206@lerdorf.com> 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> Date: Thu, 22 Dec 2011 18:50:53 +0000 Message-ID: To: Rasmus Lerdorf Cc: Keloran , Dmitri Snytkine , Alain Williams , internals@lists.php.net Content-Type: multipart/alternative; boundary=20cf3072da44ac5a0804b4b2c777 Subject: Re: [PHP-DEV] Return Type Hinting for Methods RFC From: dragoonis@gmail.com (Paul Dragoonis) --20cf3072da44ac5a0804b4b2c777 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Dec 22, 2011 at 6:41 PM, Rasmus Lerdorf wrote: > 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. > I agree with Rasmus. 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. There is need for the existing Typehinting for class types so you don't need to have is_a() function calls. This makes sense. 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. Lets not go there please.. Thanks, Paul Dragoonis. > > -Rasmus > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --20cf3072da44ac5a0804b4b2c777--