
php 函数的
参数类型可以指定为类名或
数组类型array,比如 这样是对的public function Right( My_Class $a, array $b ) 这样是错的public function Wrong( string $a, boolean $b ) 如果需要其他类型<?php// 两个类的对象$myclass = new MyClass$otherclass = new OtherClass// 致命错误:
第一个参数必须是 OtherClass 类的一个对象$myclass->test('hello')// 致命错误:第一个参数必须为 OtherClass 类的一个实例$foo = new stdClass$myclass->test($foo)// 致命错误:第一个参数不能为 null$myclass->test(null)// 正确:输出 Hello World$myclass->test($otherclass)// 致命错误:第一个参数必须为数组$myclass->test_array('a string')// 正确:输出数组$myclass->test_array(array('a', 'b', 'c'))// 正确:输出 ArrayObject$myclass->test_interface(new ArrayObject(array()))// 正确:输出 int(1)$myclass->test_callable('var_dump', 1)?>
评论列表(0条)