Re: [PATCH] Optional scalar type hinting
| From: | Jeremy Privett | Date: | Thu, 15 Nov 2007 16:34:55 +0000 |
| Subject: | Re: [PATCH] Optional scalar type hinting | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-33161@lists.php.net to get a copy of this message | ||
Richard Quadling wrote:
On 15/11/2007, Sam Barrow <sam@sambarrow.com> wrote:To your point, I think it would really only help those OCD developers among us who always use === and try to make PHP behave like a strongly typed language. --- Jeremy Privett C.E.O. & C.S.A. Omega Vortex CorporationI found a patch by Derick online to allow for scalar type hinting, and made it work with the newest snapshot of PHP 5.3. I also added the ability to type hint for resources. I would like to ask that it be added to the next PHP release. It allows type hinting for int, float, bool, string, resource, and object, I also added the ability to use the secondary keywords for all of these types (such as double, real, long, etc.). It will maintain 100% backwards compatibility, as the type hinting is 100% optional, implemented in the same way as array/class type hinting. I have the patch on my PC, please let me know where and when i can submit it. I'd be happy to do the patching and submission myself, just asking for permission here.What happens for type conversion? Is the param cast to the hinted type? The idea of type hinting for array and class is to make sure you get something appropriate. Rarely would you think of an array and cast it as an integer (or vice versa), so it makes sense. But with a string ("0"), an integer (0) or a boolean (false), they are all the same, so does this mean we would be having to cast all the params to the function/method? I imagine that it will behave the same was as the other type hinting and just bomb out if the incoming data is of the wrong type. It kind of defeats the purpose of type "hinting" if it's really just type "casting" in the method call.