Return type hinting patch

From: Date: Fri, 25 Apr 2008 15:30:10 +0000
Subject: Return type hinting patch
Groups: php.internals 
Request: Send a blank email to internals+get-37218@lists.php.net to get a copy of this message
Attached is my return type hinting patch. It allows type hinting for parameters and return values. Int, float, bool, string, num, scalar, resource, object, array, and class names are supported for both parameters and return values. Objects with __toString methods are allowed to pass for scalar and string type hints. function myTypedFunction returns int(string $stuff, bool, $things, num $amount) { return 'This will cause an error.' } I want to move the returns clause after the parameter list, but I couldn't get it to work in the parser: function x($param) returns y { return new y } Parameters and return values are strict. Int means int (to the type), etc. For type hinted parameters, null is allowed only if it is the default value. Implementations of abstract functions must be compatible both in their parameter and return types. Mismatched types will cause an error. Note: The parameter type hinting is complete. The return type hinting works, but there is a small memory leak which I do not know how to fix. Besides that it's running perfectly, it's very minor obstacle, I'm just not familiar enough with C to fix this right now.

Attachment: [text/x-patch] returntypehinting.patch
« previous php.internals (#37218) next »