Re: Return Type Hinting for Methods RFC

From: Date: Thu, 22 Dec 2011 19:22:57 +0000
Subject: Re: Return Type Hinting for Methods RFC
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to internals+get-57021@lists.php.net to get a copy of this message
On Dec 22, 2011, at 1:51 PM, Sebastian Bergmann wrote: > Am 22.12.2011 19:41, schrieb Rasmus Lerdorf: >> 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. > > Putting such code into the "correct" place does not change the problem > that you and Stas describe > > 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 ... There are cases, such as the one you pointed out, that requires type casting. We're just trying to point out a situation where, if scalars were allowed to be typed, would produce code littered with type casts. Point taken though. > > I am not advocating type hints for scalars, I am just saying that this > argument is not really a good one against it. > > -- > Sebastian Bergmann Co-Founder and Principal Consultant > http://sebastian-bergmann.de/ > http://thePHP.cc/ > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.internals (#57021) next »