Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57017 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43189 invoked from network); 22 Dec 2011 19:18:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Dec 2011 19:18:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 67.192.241.163 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 67.192.241.163 smtp163.dfw.emailsrvr.com Linux 2.6 Received: from [67.192.241.163] ([67.192.241.163:50245] helo=smtp163.dfw.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 07/EC-12618-C9283FE4 for ; Thu, 22 Dec 2011 14:18:53 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp16.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id 9BE5C403EF; Thu, 22 Dec 2011 14:18:49 -0500 (EST) X-Virus-Scanned: OK Received: by smtp16.relay.dfw1a.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id 50C644086F; Thu, 22 Dec 2011 14:18:48 -0500 (EST) Message-ID: <4EF38297.5040507@sugarcrm.com> Date: Thu, 22 Dec 2011 11:18:47 -0800 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: Dmitri Snytkine CC: 'Sebastian Bergmann' , "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> <4EF379D8.9000206@lerdorf.com> <4EF37C29.1010206@php.net> <4EF37D19.8080207@alliantinternet.com> <007e01ccc0dc$985f1cd0$c91d5670$@alliantinternet.com> In-Reply-To: <007e01ccc0dc$985f1cd0$c91d5670$@alliantinternet.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Return Type Hinting for Methods RFC From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! > is_numeric is not good enough in some cases, like when searching for value > in MongoDB where it matches agains typed value. > > function age_check(int $age) > { > // do stuff > } > > This would require less code, easier to read and will catch wrong type at > runtime easy and throw recoverable fatal error that you can catch. You can catch and do what? By that time you application has failed with no chance to recover, since you can't go back to age_check call and say "oh, sorry, when I said '1' I actually meant integer 1, please accept it!" The only thing you can do is to output a nice error message, and since this is nothing the user can correct, since it's not his problem but a code bug, it'll be something like "something went wrong, oops, please go to another page of the site and hope it will be programmed better than this one!". That's pretty much your options when using strict typed function - unless you either have strict typing throughout the whole code path(s) that lead to the age_check call or do an explicit check with explicit failure handling each time you try to call it. > the well designed IDE can also catch error in your code if your parameters > and all returnes are typed, so that will also save you a lot of time. I start to feel "well designed IDE" is a substitute for a compiler for some. PHP is not a compiled language, however, at least not yet - and since it's not, relying on mythical "well designed IDE" to perform the function that compiler performs in static-typed compiled languages is, IMHO, misguided. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227