Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Operator Overloading

<?php 

use BcMath\Number;

$a = new Number('1.005691112');
$b = new Number('2.567891112');

$result = $a * $b; 

echo $result->round(2);
echo PHP_EOL;
echo $result;
echo PHP_EOL;
echo 1.005691112 * 2.567891112;
echo PHP_EOL;
echo 'precision is '.ini_get('precision');

PHP has no operator overloading in the userland, but it may be achieved by using an extension.

Bcmath has taken advantage of it since PHP 8.3, where it introduced the Number class.

With feature, it is possible to go beyond the 14 decimal digits of standard PHP configuration.

On the other hand, the underlying library’s limitation are also applied, so using the ** operator on decimal Number yield a exponent cannot have a fractional part, which does not appear in the standard PHP operation.

See Also

PHP Error Messages

PHP Features

Last updated: 09 November 2026