Re: Return type hints
| From: | Stanislav Malyshev | Date: | Mon, 14 Apr 2008 16:55:59 +0000 |
| Subject: | Re: Return type hints | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-37004@lists.php.net to get a copy of this message | ||
Hi!
Let me turn your question around: Why on earth would someone restrict a function to int when string works just as well? function int foo_flexible(scalar $x) { return $x + 42; } $foo = foo_flexible($value);Now let's think - what happens if $x is *not* scalar? So the real code would be like this: function foo_flexible(scalar $x) { return $x + 42; } if(!is_scalar($value)) { $foo = foo_flexible($value); } else { // ok, what do I do now? } And so for each instance. Ugly.
That said, I'll be using function foo($x) { return $x + 42; } anyway and let PHP warnings take care of the rest ;-)Amen to that. -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com