Php 类型前带询问点的变量声明
Php variable declaration with an interrogation point before the type
在 php 中,以下两个变量声明在过程模式和 class 内部有什么区别:
string $str; // without ? before the type
?string $str; // with ? before the type
谢谢你的灯
变量$str
只能是类型string
:
string $str;
变量 $str
的类型可以是 string
或 null
:
?string $str;
在 php 中,以下两个变量声明在过程模式和 class 内部有什么区别:
string $str; // without ? before the type
?string $str; // with ? before the type
谢谢你的灯
变量$str
只能是类型string
:
string $str;
变量 $str
的类型可以是 string
或 null
:
?string $str;