我已经安装了decimal-ext扩展和php decimal/lavel composer包。我用它来比较大的十进制数字。在我的笔记本电脑上,一切都正常工作,但在我的暂存服务器上,出现了以下错误:
Return value of DecimalDecimal::compareTo() must be of the type int, none returned
这是代码:
(new Decimal($value))->compareTo($maxNumber) == -1;
正如我所说,我的笔记本电脑上没有出现这个错误。
Laravel:5.8PHP:7.4.3服务器:Ubuntu 18.04
我在这方面花了一些时间,但还是想明白了。未在服务器的php.ini文件中加载十进制文本扩展名。Php没有抛出关于缺少扩展的异常,而是关于错误的返回类型的异常,因为Decimal类是实际加载的(它是通过composer安装的(。我可以实例化一个实例,但缺少实现:
/**
* Ordering
*
* This method is equivalent to the `<=>` operator.
*
* @param mixed $other
*
* @return int 0 if this decimal is considered is equal to $other,
* -1 if this decimal should be placed before $other,
* 1 if this decimal should be placed after $other.
*/
public function compareTo($other): int {}