整数和整数之间的 PHP 差异
2022-08-30 20:13:30
在 PHP 中 和 之间有什么区别吗?int
integer
哪个是较新的或更推荐的用途?
$a = (int)"3 euros";
echo $a; // $a==3
$a = (integer)"3 euros";
echo $a; // $a==3
在 PHP 中 和 之间有什么区别吗?int
integer
哪个是较新的或更推荐的用途?
$a = (int)"3 euros";
echo $a; // $a==3
$a = (integer)"3 euros";
echo $a; // $a==3
当我们使用 php 7.0+ 中的类型提示时,差异就出现了。
这是有效的
function getId(): int
{
return $id;
}
这不是
function getId(): integer
{
return $id;
}
第二个会期望你返回一个“类整数”的对象,这将导致一个奇怪的句子:
Uncaught TypeError: Return value of getId() must be an instance of integer, integer returned in ...