tags:

views:

38

answers:

2

In this example:

/**
 *
 * @param <type> $foo
 * @return <type> 
 */
function do_something($foo) {
    return $foo->really_do_something();
}

How to indicate that $foo must be of the class Foo?

+4  A: 
/**
 *
 * @param Foo $foo
 * @return <type> 
 */
function do_something(Foo $foo) {
    return $foo->really_do_something();
}
usoban
Wow! I didn't know about the type hinting. Thanks.
Ricardo
+1  A: 

More recent versions of PHP (PHP 5 onwards I think) have parameter types:

function do_something(Foo $foo) {
   return $foo->really_do_something();
}

Which will throw an exception if $foo is not a type of Foo.

I assume phpDoc picks this up

Yacoby
Thanks for helping man!
Ricardo