It would give you similar benefits to input type hinting, but instead of "Functions are now able to force parameters to be objects...", it would also read "Calling functions are now able to expect return types to be objects...". If a function was defined to return object Z, but instead returned false, then obviously there is something wrong and it could be caught before calling code sees it expecting it to be something else.

This feature does not replace good documentation, good testing, or provide any new functionality that could not be recreated by other means. However, it provides a different and often better solution to common problems. Many current PHP projects already have some sort of "module" or "plugin" system how they make use of modules and return type checking (if at all) vary wildly. With THRs future projects would be able to make use of a slightly more advanced language with better support for modular programming.

If I, or someone else decided to make a patch for this, and assuming it worked exactly like I described, would it be accepted?

Stanislav Malyshev wrote:
It could be interesting to know, if the reason why this hasn't been
implemented already, is technical one, or a design decision?

I think it's design one since nobody took care to design it :) I personally don't see much need for it, since PHP is not a compiled language, so there's little use for specific syntax of prescribing value types. Since PHP has no concept of variable type, it's not clear what return type hinting would give you that good documenting practices and a decent IDE won't.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to