3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Decimal { private string $value; public function __construct(string $value) { $this->value = $value; } public function toFixed(int $scale): string { // rough example for adjusting precision - do not use return bcadd($this->value, '0', $scale); } } class Entity { #[ORM\Column(type: 'decimal', precision: 10, scale: 4)] private string $subtotal = '0.0'; // name as desired public function getSubtotalDecimal(): Decimal { return new Decimal($this->subtotal, 4); } public function getSubtotal(): string { return $this->subtotal; } // see Union Types public function setSubtotal(string|Decimal $subtotal): self { if ($subtotal instanceof Decimal) { $subtotal = $subtotal->toFixed(4); } $this->subtotal = $subtotal; return $this; } } $decimal = new Decimal("1337.987654321"); $entity = new Entity(); $entity->setSubtotal($decimal); echo $entity->getSubtotal() . \PHP_EOL; echo $entity->getSubtotalDecimal()->toFixed(4) . \PHP_EOL;

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.120.0120.00820.80
8.4.110.0130.01022.79
8.4.100.0120.00820.52
8.4.90.0140.00618.89
8.4.80.0100.01220.48
8.4.70.0100.00317.97
8.4.60.0100.01118.63
8.4.50.0120.00817.79
8.4.40.0100.00019.47
8.4.30.0060.00320.52
8.4.20.0070.01017.86
8.4.10.0060.00320.51
8.3.250.0090.00718.66
8.3.240.0110.00518.70
8.3.230.0060.00216.95
8.3.220.0040.00418.83
8.3.210.0100.00616.78
8.3.200.0130.00616.58
8.3.190.0080.00717.13
8.3.180.0100.01018.30
8.3.170.0070.01016.94
8.3.160.0090.00918.47
8.3.150.0070.00017.11
8.3.140.0000.01017.32
8.3.130.0030.00618.39
8.3.120.0090.01218.97
8.3.110.0040.00420.94
8.3.100.0070.00724.06
8.3.90.0090.00626.77
8.3.80.0060.00316.50
8.3.70.0070.00716.63
8.3.60.0090.00616.88
8.3.50.0210.00318.36
8.3.40.0110.01119.30
8.3.30.0110.00419.27
8.3.20.0000.00824.18
8.3.10.0080.00024.66
8.3.00.0000.00826.16
8.2.290.0100.00720.43
8.2.280.0060.00320.05
8.2.270.0070.01117.18
8.2.260.0110.00718.90
8.2.250.0050.00216.77
8.2.240.0130.00318.91
8.2.230.0090.00022.58
8.2.220.0040.00437.54
8.2.210.0110.00726.77
8.2.200.0000.00916.63
8.2.190.0130.01016.63
8.2.180.0100.00725.92
8.2.170.0040.01118.95
8.2.160.0100.00322.96
8.2.150.0000.00725.66
8.2.140.0070.00024.66
8.2.130.0040.00426.16
8.2.120.0080.00020.68
8.2.110.0050.00520.55
8.2.100.0030.00620.52
8.1.330.0110.00922.05
8.1.320.0070.00516.43
8.1.310.0030.00518.50
8.1.300.0030.01217.91
8.1.290.0090.00318.88
8.1.280.0090.00625.92
8.1.270.0080.00023.99
8.1.260.0080.00026.35
8.1.250.0180.00028.09
8.1.240.0030.00618.50
8.1.230.0030.00618.95
8.0.170.0090.00416.87

preferences:
27.91 ms | 403 KiB | 5 Q