PHP教程
PHP Mysql
PHP面向对象
PHP常用

PHP 类型提示

PHP 输入提示

简单来说,类型提示意味着提示函数只接受给定的数据类型。 用技术术语来说,我们可以说类型提示是一种我们可以强制函数接受所需数据类型的方法。 在 PHP 中,我们可以对对象、数组和可调用数据类型使用类型提示。

示例 1

<?php
    
    class a
    {
        public $c= "hello lidihuo";
    }
    //create function with class name argument
    function display(a $a1)
    {
        //call variable
        echo $a1->c;
    }
    display(new a());
?>
输出:
Type Hinting

示例 2

<?php
    
    class Test1
    {
        public $var= "hello lidihuo and SSSIT";
    }
    //create function with class name argument
    function typehint(Test1 $t1)
    {
        //call variable
        echo $t1->var;
    }
    //call function with call name as a argument
    typehint(new Test1());
?>
输出:
Type Hinting
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4