企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## **类型约束** PHP的类方法和函数中可实现[类型约束](http://php.net/manual/zh/language.oop5.typehinting.php),7以下参数只能指定**类**、**数组**(PHP 5.1 起)、**接口**、**callable**(PHP 5.4 起) 四种类型,参数可默认为NULL,PHP并不能约束标量类型或其它类型。 ``` class Person {  public $name = '张三'; } // 对象可以做类型约束:类名 抽象类名 接口 function fun(Person $a) {  echo $a->name; } // fun(1234); // 报错 $p = new Person; fun($p); // 数组类型约束 function demo(Array $a) {  var\_dump($a); } //demo('abc');//这个也会报错 demo(\['username'=>'zhangsan'\]); ```