3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Entity { private Decimal $subtotal; public function getSubtotal() { return $this->subtotal; } public function setSubtotal(Decimal $value) { $this->subtotal = $value; return $this; } } class Decimal { private string $value; public function __construct(string $value) { $this->value = $value; } public function getValue() { return $this->value; } public function toFixed(int $scale): Decimal { // rough example for adjusting precision - do not use return new self(bcadd($this->value, '0', $scale)); } } //////////////// $entity = new Entity(); $entity->setSubtotal((new Decimal('1337.987654321'))->toFixed(4)); echo $entity->getSubtotal()->getValue();
Output for 7.4.33, 8.5.1 - 8.5.7
Fatal error: Uncaught Error: Call to undefined function bcadd() in /in/3DN9G:39 Stack trace: #0 /in/3DN9G(46): Decimal->toFixed(4) #1 {main} thrown in /in/3DN9G on line 39
Process exited with code 255.
Output for 7.4.0 - 7.4.32, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.21, 8.5.0
1337.9876

preferences:
101.26 ms | 1251 KiB | 4 Q