未定义函数 bcsub()

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

我在本地 Laravel 中使用此代码并且成功了

public function dateForHuman($custom_timestamp) 
  {
        $date = bcsub($custom_timestamp, 25569, 10) * 86400;
        return date('Y-m-d H:i:s', $date);
  }

但是当我在我的服务器中尝试时,响应错误 Undefined Function bcsub()

php laravel laravel-7
2个回答
1
投票

根据 PHP 文档,BCMath 默认情况下在 Linux 服务器上的 PHP7 中不可用。

bcmath 不会在 linux(ubuntu 服务器)上随 php 7 自动安装,您必须使用: sudo apt-get install php-bcmath

请使用apt-get安装:

sudo apt-get install php-bcmath

来源:http://php.net/manual/en/bc.installation.php


0
投票

接受的答案提供了完美的信息,只需确保也启用它并重新启动服务器即可。 启用命令:sudo phpenmod bcmath 检查是否启用的命令: php -m | grep bcmath 重启服务器的命令: sudo systemctl restart apache2

© www.soinside.com 2019 - 2024. All rights reserved.