If I remember correctly, you can set the class name in front of the parameter to limit the type of the variable to the class, however, I'm not sure about the array actual use here.
EDIT: Apparently my PHP is a bit rusty. According to http://php.net/manual/en/language.oop5.typehinting.php :
PHP 5 introduces Type Hinting. Functions can now force objects to be objects (by specifying the class name in the function prototype) or arrays (starting with PHP 5.1). However, if NULL is used as the default parameter value, it will be resolved as an argument for any subsequent call.
For instance:
// An example class class MyClass { /** * A test function * * First parameter must be an object of type OtherClass */ public function test(OtherClass $otherclass) { echo $otherclass->var; } /** * Another test function * * First parameter must be an array */ public function test_array(array $input_array) { print_r($input_array); } } // Another example class class OtherClass { public $var = 'Hello World'; }
// An example class class MyClass { /** * A test function * * First parameter must be an object of type OtherClass */ public function test(OtherClass $otherclass) { echo $otherclass->var; } /** * Another test function * * First parameter must be an array */ public function test_array(array $input_array) { print_r($input_array); } } // Another example class class OtherClass { public $var = 'Hello World'; }
source share