Re: Return type hints

From: Date: Thu, 28 Sep 2006 19:54:02 +0000
Subject: Re: Return type hints
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-25872@lists.php.net to get a copy of this message
On Wed, September 13, 2006 6:01 am, Richard Quadling wrote: > The issue then becomes what would happen to a value of the wrong type? > > You either have the option of using PHP's own internal casting > mechanism, so f(int $i_int_expected) would internally cast the > supplied parameter as an int or you have to produce a WARNING with a > "parameter of the wrong type" message. But then what is passed to the > function? This would have to be determined somehow. Could I just point out that MANY PHP functions do things like this: /* returns int for blah blah * returns false in case of error */ function foo($x){ if (world_has_ended()) return false; } So if you're going to insist on type hints, can we not at least make it sensible and have syntax like: int|bool function foo (){ } So foo() returns int or bool. Otherwise, you end up with (int) false strewn all through your code, and it looks all messy. There's a REASON why I'm writing PHP and not C, folks... :-) -- Like Music? http://l-i-e.com/artists.htm

« previous php.internals (#25872) next »