Re: Return type hinting patch

From: Date: Fri, 25 Apr 2008 17:55:12 +0000
Subject: Re: Return type hinting patch
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-37224@lists.php.net to get a copy of this message
On Fri, 2008-04-25 at 10:06 -0700, Stanislav Malyshev wrote: > Hi! > > In general, it'd be very nice to have some definition of the proposed > feature beyond the patch. It would probably answer some of my questions > that follow :) > > > parameters and return values. Objects with __toString methods are > > allowed to pass for scalar and string type hints. > > What about objects that can be converted to other types (cast_object > handler)? Hadn't thought about these, don't see why it couldn't be added though. > > function myTypedFunction returns int(string $stuff, bool, $things, num > > $amount) { > > return 'This will cause an error.' > > } > > What about return "1"? Also I notice it introduces new keyword - > returns. Is it necessary? Each new keyword means broken code. We could probably find a way to use the return keyword or another syntax, I just did it like this for simplicity. > > Parameters and return values are strict. Int means int (to the type), > > Meaning that int would reject 1.0, true and "1"? bool would reject 1 and > 0 and null? Ouch, ouch, ouch. As it is now, yes, this works just like parameter hints. Could be changed if decided upon.

« previous php.internals (#37224) next »