PHP 5 number_format() 不在本地返回异常消息,但在生产中返回

问题描述 投票:0回答:1

我在 PHP 5 遗留项目环境(本地和生产)中有以下 PHP 代码片段:

<?php

ini_set('display_errors', 'on');
error_reporting(E_ALL);
error_reporting(-1);
ini_set('error_reporting', E_ALL);

try {
    number_format("");
 } catch (\Exception $e) {
     throw new Exception($e->getMessage());
 }

?>

我知道这是一个问题,因为

number_format
期望浮点或双精度。但是,它不会在本地主机中触发异常,但会在生产中触发异常。

实际消息是

Warning: number_format() expects parameter 1 to be double, string given in /path-to-file.php

我还尝试将

ini_set('display_errors', 'on');
更改为
ini_set('display_errors', 1);
并将
error_reporting(E_ALL);
更改为
error_reporting(E_ALL | E_STRICT);
但它不会返回预期的异常。

我还尝试删除

try/catch
并按原样使用
number_format
,以便弹出异常错误,但未显示异常错误。

还尝试在 php.ini 中添加

display_errors = on
相同的结果。

php exception error-handling php-5.3
1个回答
0
投票

检查本地主机和生产环境之间的服务器配置是否存在任何差异。这可能包括 php.ini、.htaccess 文件中的设置或特定于服务器的配置。 试试这个

ini_set('display_errors', 'on');
error_reporting(E_ALL);

try {
    number_format("");
} catch (\Exception $e) {
    echo "Caught exception: " . $e->getMessage();
}
© www.soinside.com 2019 - 2024. All rights reserved.