lumisys/bcmath_compat

PHP 5.x/7.x polyfill for bcmath extension

1.0.5.1 2020-06-05 18:19 UTC

This package is auto-updated.

Last update: 2024-04-03 06:18:12 UTC


README

Software License Build Status

PHP 5.x/7.x polyfill for bcmath extension

Installation

With Composer:

$ composer require phpseclib/bcmath_compat

Installation On Heroku

bcmath_compat does not install the normal way on Heroku / Composer < 2.0 because Heroku uses modified composer.json's. Composer 2 makes this a non-issue.

In light of this the way to install this on Heroku with Composer < 2.0 is to do the following:

$ composer require phpseclib/bcmath_compat:1.0.4

Limitations

  • extension_loaded('bcmath')

    bcmath_compat cannot make this return true. The recommended remediation is to not do this.

  • ini_set('bcmath.scale', ...)

    You cannot set configuration options for extensions that are not installed. If you do ini_set('bcmath.scale', 5) on a system without bcmath installed then ini_get('bcmath.scale') will return false. It's similar to what happens when you do ini_set('zzz', 5) and then ini_get('zzz'). You'll get false back.

    The recommended remediation to doing ini_set('bcmath.scale', ...) is to do bcscale(...). The recommended remediation for doing ini_get is (if you're using PHP >= 7.3.0) to do bcscale() or (if you're using PHP < 7.3.0) to do max(0, strlen(bcadd('0', '0')) - 2).

    Note that ini_get always returns a string whereas the recommended remediations return integers.