Can We Restrict PHP Variables to accept only certain type of values

后端 未结 3 1270
深忆病人
深忆病人 2021-01-03 08:23

i am wondering is it possible to restrict php variable to accept only certain type of variable it is defined to accept.

e-g if we see in C#

public in         


        
3条回答
  •  情书的邮戳
    2021-01-03 08:38

    You have to made it by your own hands, example :

    function setInt(&$var, $value) {
        if(!is_integer($value) {
            throw new Exception("Integer wanted " . gettype($value) . " received");
        }
        $var = $value;
    }
    

提交回复
热议问题