phpseclib / bcmath_compat
PHP 5.x-8.x polyfill for bcmath extension
Installs: 17 994 370
Dependents: 10
Suggesters: 5
Security: 0
Stars: 165
Watchers: 3
Forks: 5
Open Issues: 1
Requires
- phpseclib/phpseclib: ^3.0
Requires (Dev)
- phpunit/phpunit: ^4.8.35|^5.7|^6.0|^9.4
- squizlabs/php_codesniffer: ^3.0
Suggests
- ext-gmp: Will enable faster math operations
Provides
- ext-bcmath: 8.1.0
README
PHP 5.x-8.x polyfill for bcmath extension
Installation
With Composer:
$ composer require phpseclib/bcmath_compat
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 thenini_get('bcmath.scale')
will returnfalse
. It's similar to what happens when you doini_set('zzz', 5)
and thenini_get('zzz')
. You'll getfalse
back.The recommended remediation to doing
ini_set('bcmath.scale', ...)
is to dobcscale(...)
. The recommended remediation for doingini_get
is (if you're using PHP >= 7.3.0) to dobcscale()
or (if you're using PHP < 7.3.0) to domax(0, strlen(bcadd('0', '0')) - 2)
.Note that
ini_get
always returns a string whereas the recommended remediations return integers.