Re: Return Type Hinting for Methods RFC

From: Date: Thu, 22 Dec 2011 20:14:28 +0000
Subject: Re: Return Type Hinting for Methods RFC
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  Groups: php.internals 
Request: Send a blank email to internals+get-57032@lists.php.net to get a copy of this message
On Dec 22, 2011, at 3:06 PM, Stas Malyshev wrote: > Hi! > >> I'm going to have to disagree with you there. Type hinting DOES save >> me a LOT of effort in development. I can stop worrying about checking >> to make sure the parameter that I got is what I want it to be, and >> just use it. The runtime will check and enforce that for me. When > > I'm sorry but I don't see how what you describe is good. You stopped worrying about > checking inside the function, but unless you have started checking outside the function you've > just made your code less robust that it was before. While in the case of strict class typing the > case of mismatched classes is so rare that occasional failure is easily identifiable, you > didn't really improve your code. I agree that it makes you type less - but the cost of it is > your application also does less - you don't have a capability of gracefully handling a problem > any longer. Again, with object strict typing, this might be OK since failures are very rare and > usually a result of obvious mistakes caught early in testing - but if they are not, you didn't > really gain much. I wouldn't be opposed to moving from raising an E_RECOVERABLE_ERROR to some type of exception. In fact, I'd support it (in a discussion over that RFC). Your argument of not checkout outside the function is exactly why many are against type hinting scalars to begin with. A generic "scalar" keyword being added would help some, but only protect against objects, resources and arrays. > -- > 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 >

« previous php.internals (#57032) next »