Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57014 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39188 invoked from network); 22 Dec 2011 19:05:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Dec 2011 19:05:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=dsnytkine@Ultralogistics.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=dsnytkine@Ultralogistics.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain Ultralogistics.com from 64.197.110.172 cause and error) X-PHP-List-Original-Sender: dsnytkine@Ultralogistics.com X-Host-Fingerprint: 64.197.110.172 thrud.alliantinternet.com Received: from [64.197.110.172] ([64.197.110.172:48649] helo=thrud.alliantinternet.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 15/0C-12618-F5F73FE4 for ; Thu, 22 Dec 2011 14:05:03 -0500 Received: by thrud.alliantinternet.com (Postfix, from userid 1001) id 86EC9174329; Thu, 22 Dec 2011 14:04:59 -0500 (EST) To: "'Stas Malyshev'" , "'Sebastian Bergmann'" Cc: 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> In-Reply-To: <4EF37D19.8080207@alliantinternet.com> Date: Thu, 22 Dec 2011 14:04:56 -0500 Message-ID: <007e01ccc0dc$985f1cd0$c91d5670$@alliantinternet.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Thread-Index: AczA215W7kyVApx4QO+XfJ+iRlw1EwAAFjqw Content-Language: en-us Subject: RE: [PHP-DEV] Return Type Hinting for Methods RFC From: dsnytkine@Ultralogistics.com ("Dmitri Snytkine") 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. 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. Dmitri Snytkine Web Developer Ultra Logistics, Inc. Phone: (888) 220-4640 x 2097 Fax: (888) 795-6642 E-Mail: dsnytkine@ultralogistics.com Web: www.ultralogistics.com "A Top 100 Logistics I.T. Provider in 2011" -----Original Message----- From: Stas Malyshev [mailto:smalyshev@sugarcrm.com] Sent: Thursday, December 22, 2011 1:55 PM To: Sebastian Bergmann Cc: internals@lists.php.net Subject: Re: [PHP-DEV] Return Type Hinting for Methods RFC Hi! > function age_check($age) > { > if (!is_int($age)) { > throw new InvalidArgumentException; > } > } > > With the above code, the caller needs to cast and the writer of the > age_check() function has to copy/paste/adapt these checks to all the > correct places ... That's because you should be using is_numeric in this context ;) And have an answer on the question "what happens if it's not" that does not involve "throwing exception that nobody is going to catch". Of course, you can't design proper library in one line. The idea is that strict typing doesn't make such design easier, since it does not lead to less work. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php