解决PHP未定义函数bcmul错误及bcmath扩展安装配置
在进行网络支付服务器的迁移操作期间,观察到支付功能无法正常运行。
当前PHP运行环境版本为5.3.3,操作系统为Red Hat 4.1.2-54。检查Apache的错误日志后,定位到加密文件/php_rsa.php第xxx行出现报错:PHP Fatal error: Call to undefined function bcmul()。
解决方案是通过命令行安装缺失的扩展模块。执行命令yum install php-bcmath即可成功安装并解决该函数未定义的问题。
如果在执行安装命令时遇到以下依赖冲突提示:
复制代码 代码如下: Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.yun-idc.com * extras: mirrors.yun-idc.com * rpmforge: ftp.riken.jp * updates: mirrors.yun-idc.com Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package php-bcmath.x86_64 0:5.1.6-40.el5_9 set to be updated --> Processing Dependency: php-common = 5.1.6-40.el5_9 for package: php-bcmath --> Running transaction check ---> Package php-common.x86_64 0:5.1.6-40.el5_9 set to be updated --> Processing Conflict: php53-common conflicts php-common --> Finished Dependency Resolution php53-common-5.3.3-13.el5_9.1.x86_64 from installed has depsolving problems --> php53-common conflicts with php-common Error: php53-common conflicts with php-common You could try using --skip-broken to work around the problem You could try running: package-cleanup --problems package-cleanup --dupes rpm -Va --nofiles --nodigest
面对上述冲突情况,应当先执行yum update命令更新现有软件包,随后再运行yum install php53-bcmath进行安装,从而顺利完成扩展部署。
补充说明,bcmath属于PHP内置的数学扩展库。开发者可通过调用bcscale()函数来设定全局默认的小数位数。该扩展中的核心乘法函数定义为:string bcmul ( string $left_operand , string $right_operand [, int $scale ] )。具体使用示例如下:
此函数在php.ini配置文件中的相关选项设置如下: 复制代码 代码如下: [bcmath] ; Number of decimal digits for all bcmath functions. ; http://www.php.net/manual/en/bc.configuration.php#ini.bcmath.scale bcmath.scale = 0