Re: Return Type Hinting for Methods RFC
| From: | Stas Malyshev | Date: | Thu, 22 Dec 2011 18:39:06 +0000 |
| Subject: | Re: Return Type Hinting for Methods RFC | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-57008@lists.php.net to get a copy of this message | ||
Hi!
That said, PHP is not Java, and type hinting in PHP is very different. It is, in fact, type *hinting*. This is a runtime feature. Only interface validation is verified at compile time, so we have to consider performance vs. feature in these cases.Naming it "hinting" was probably the worst mistake in PHP documentation since "safe mode". The word hinting implies it's just something non-mandatory, that can be used if needed, but ignored if not. While using typing is indeed not mandatory, once used, it *is* mandatory check that can not be ignored and produces fatal error in case of mismatch. The only difference is that in Java this error is detected in compile time, while in PHP it is a runtime failure, usually taking down the application in the middle of processing, without possibility of proper recovery. I'm not sure we're having the better deal here. Performance is irrelevant here, more or less, since typing checks won't take much time unless you have insanely deep class hierarchies (you have to compare object's class and probably his parents' to the prescribed type). Stability and maintainability of such code is an issue. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227