How can I specify the argument type as an array? Say I have a class named \'Foo\':
class Foo {}
and then I have a function that accepts tha
function getFoo()
Generally, you would then have an add method that would typehint to Foo
function addFoo( Foo $f )
So, the getter would return an array of Foo's and the add method can ensure you only had Foo's to the array.
EDIT Removed the argument from the getter. I don't know what I was thinking, you don't need an argument in a getter.
EDIT just to display the a full class example:
class FooBar
{
/**
* @return array
*/
private $foo;
public function getFoo()
{
return $foo;
}
public function setFoo( array $f )
{
$this->foo = $f;
return $this;
}
public function addFoo( Foo $f )
{
$this->foo[] = $f;
return $this;
}
}
You generally, and probably shouldn't, have the setter method since you have the add method to help ensure $foo is an array of Foo's but it helps illustrate what is going on in the class.