第一步、首先下载我们本节课程所需要用到的php中的类型约束类库:
第二步、下载完成之后找到我们需要的php类文件,解压至我们本地目录,创建新的php文件!
第三步、完成之后,我们要在新的php文件里调用这类,以及实例化该类:
<?php
include_once "test.php";//引入类文件
$test = new Test();
//函数调用的参数与定义的参数类型不一致时,会抛出一个可捕获的致命错误。
$test->test_array(array(1));echo "<br>";
$test->test_class(new Test1());echo "<br>";
$test->test_callable('print_r', 1);echo "<br>";
$test->test_interface(new ArrayObject(array()));echo "<br>";
$test->test_class_with_null();
?>运行此文件,得到结果如下图所示:

| 欢迎光临 一起源码网 (https://www.171739.xyz/) | Powered by Discuz! X3.3 |