Type hints still coming to PHP?
Damn, will PHP finally grow up to a real OO programming language? Today there was another proposal for using type hints. This is partly already possible, but this one goes much further. Currently you can only type hint for array and objects. No default types like string, int or something. You can't also type hint the return value of the function. But it's probably all coming in PHP5.3.

Damn I would love to this implemented, because it would save a lot of validation work for us. It's also more clear what type of parameter you want in a function. For those wo don't want to use type hinting: here's the good news, it's completely optional.
Some examples of the syntax and how it works, click read more.
Return value hints
Using with namespaces
- namespace foo;
- class test { }
- class bar {
- return $instance;
- }
- }
- bar::testing(new test);
- bar::testing(new stdClass); // Catchable fatal error: The returned value should be instance of foo::test
Using inheritance
- interface ITest { }
- class bar implements ITest { }
- class foo extends bar { }
- function (Itest) testing($instance) {
- return $instance;
- }
- testing(new bar);
- testing(new foo);
- testing(new stdClass); // Catchable fatal error: The returned value must implement interface Itest
Parameter Hints
Integer
- function test(integer $value) {
- }
- test(1);
- test(1337);
- test(-1);
- test(1.0); // Catchable fatal error: Argument 1 passed to test() must be of the type integer, float given
- function test(integer $value = '1') {
- }
- // Fatal error: Default value for parameters with integer type hint can only be the exact type or NULL
Resources
- function test(resource $value) {
- }
- test(NULL); // Catchable fatal error: Argument 1 passed to test() must be of the type resource, null given
Source of the examples + some more:
http://wiki.php.net/rfc/typehint

