Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57033 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71573 invoked from network); 22 Dec 2011 20:35:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Dec 2011 20:35:11 -0000 Authentication-Results: pb1.pair.com header.from=johncrenshaw@priacta.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=johncrenshaw@priacta.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain priacta.com designates 64.95.72.243 as permitted sender) X-PHP-List-Original-Sender: johncrenshaw@priacta.com X-Host-Fingerprint: 64.95.72.243 mxout.myoutlookonline.com Received: from [64.95.72.243] ([64.95.72.243:57515] helo=mxout.myoutlookonline.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B6/33-12618-E7493FE4 for ; Thu, 22 Dec 2011 15:35:11 -0500 Received: from mxout.myoutlookonline.com (localhost [127.0.0.1]) by mxout.myoutlookonline.com (Postfix) with ESMTP id 88941416EE9; Thu, 22 Dec 2011 15:35:08 -0500 (EST) X-Virus-Scanned: by SpamTitan at mail.lan Received: from HUB025.mail.lan (unknown [10.110.2.1]) by mxout.myoutlookonline.com (Postfix) with ESMTP id 0ED7D416E96; Thu, 22 Dec 2011 15:35:08 -0500 (EST) Received: from MAILR001.mail.lan ([10.110.18.27]) by HUB025.mail.lan ([10.110.17.25]) with mapi; Thu, 22 Dec 2011 15:35:05 -0500 To: Paul Dragoonis , Rasmus Lerdorf CC: Keloran , Dmitri Snytkine , Alain Williams , "internals@lists.php.net" Date: Thu, 22 Dec 2011 15:35:02 -0500 Thread-Topic: [PHP-DEV] Return Type Hinting for Methods RFC Thread-Index: AczA2sbYubqOmbjnQN2+imRUjAVAsQAAneaA 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> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: RE: [PHP-DEV] Return Type Hinting for Methods RFC From: johncrenshaw@priacta.com (John Crenshaw) From: Paul Dragoonis [mailto:dragoonis@gmail.com]=20 > On Thu, Dec 22, 2011 at 6:41 PM, Rasmus Lerdorf wrot= e: > > > 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,=20 > > and as has been pointed out many times on this list, type hinting for=20 > > interchangable scalar types is a really bad idea. It will push all=20 > > type checking up to the caller of the underlying functions/methods.=20 > > PHP is primarily a Web scripting language and the Web isn't typed.=20 > > 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=20 > > just doesn't make any sense. It would cause everyone to have to start=20 > > 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=20 > > doesn't want to accept type-juggled arguments, then it is easy enough=20 > > to do a strict type check in the function itself. This puts the effort= =20 > > 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 ou= t 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 _need= ed_ scalar typehints then it wouldn't have been as popular. > There is need for the existing Typehinting for class types so you don't n= eed to have is_a() function calls. This makes sense. > Scalars are VERY powerful in PHP, because of its loose typed nature. Havi= ng a 'numeric' typehint makes sense, because it can be an int, float, or st= ring. Adding typehints like 'int' and 'float' will only piss people off, an= d 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,=20 > > visit: http://www.php.net/unsub.php > > > > Slightly off topic, but I keep seeing this problem: "PHP is not language X" is a terrible argument. This is a smokescreen desig= ned to insult the other person, belittle their concerns, and avoid discussi= ng the real issue. This doesn't advance the discussion at all.=20 Concluding that PHP is popular because you can't {insert requested feature = here} is also ridiculous but it happens again and again whenever language f= eatures are discussed. PHP is popular independent of not {insert missing fe= ature here}. It is popular because it was on the scene early, has good serv= er support, and does an excellent job of making it trivial to handle most s= imple web requests. Nobody wants to be told to shut up and go use language X. Let's discuss things on their own merits. /rant John Crenshaw Priacta, Inc.