我试图理解为什么 intval PHP 函数的行为在 PHP 7 和 8 之间有所不同。
例如,在像这样的测试脚本中
<?php
echo "test on " . phpversion() . " \n";
$test_var = "home";
echo "test_var is: " . $test_var . " \n";
if ( $test_var == intval($test_var) ) {
echo "same \n";
} else {
echo "not same \n";
}
echo "intval of test_var is: " . intval($test_var) . " \n";
...我认为它应该总是“不相同”,但它不在 PHP 7 中。
所以在 PHP 7 中,脚本输出...
test on 7.4.33
test_var is: home
same
intval of test_var is: 0
在 PHP 8 中,脚本输出...
test on 8.1.2-1ubuntu2.14
test_var is: home
not same
intval of test_var is: 0
谁能解释一下为什么 PHP7 会这样?
https://www.php.net/manual/en/function.intval.php的文档没有解释。