3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { private int $i = 1; // インスタンスが保持する変化する値 public function __toString(): string { // 文字列に変換されるたびに i の値が増えます。 return (string)$this->i++; } } // インスタンスをグローバル定数に割り当てます // これは PHP 8.1 から可能になった"引数デフォルト値にNew"の機能です // @see https://www.php.net/releases/8.1/ja.php#new_in_initializers // @see https://wiki.php.net/rfc/new_in_initializers const CONSTANT = new A; class B { // 新たな定数を文字列結合で構築します public const ClassConstant1 = '' . CONSTANT; public const ClassConstant2 = '' . CONSTANT; public const ClassConstant3 = '' . CONSTANT; public const ClassConstant4 = '' . CONSTANT; } // 定数を呼び出します // 呼び出したタイミングで定数が評価されます // これにより定義上で末尾ながらも最初に呼んだ ClassConstant4 が 1 を持ち、 // 最後に呼んだ ClassConstant1 が 4 を持ちます var_dump(B::ClassConstant4);// string(1) "1" var_dump(B::ClassConstant3);// string(1) "2" var_dump(B::ClassConstant2);// string(1) "3" var_dump(B::ClassConstant1);// string(1) "4" // 一度評価されるとその後は定まった値です var_dump(B::ClassConstant4);// string(1) "1" /* ↑の var_dump 群ではなく、次のコードを実行するとまた定数の値が変わります */ var_dump(B::ClassConstant1);// string(1) "1" var_dump(B::ClassConstant2);// string(1) "2" var_dump(B::ClassConstant3);// string(1) "3" var_dump(B::ClassConstant4);// string(1) "4"

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.20.0100.01020.51
8.4.10.0040.01622.00
8.3.150.0090.00918.79
8.3.140.0110.00717.23
8.3.130.0030.00518.32
8.3.120.0110.00719.10
8.3.110.0000.00920.94
8.3.100.0060.00316.80
8.3.90.0030.00616.75
8.3.50.0070.00416.38
8.2.260.0040.01418.38
8.2.250.0040.00416.54
8.2.240.0060.01217.46
8.2.230.0120.00322.58
8.2.220.0030.00616.57
8.2.210.0080.00016.75
8.1.310.0180.00018.57
8.1.300.0060.00318.74
8.1.70.0070.00417.39
8.1.60.0000.01017.52
8.1.50.0070.00317.45
8.1.40.0030.00717.41
8.1.30.0000.01117.64
8.1.20.0000.00817.57
8.1.10.0080.00417.42
8.1.00.0070.00317.52
8.0.200.0040.00816.85
8.0.190.0040.00716.93
8.0.180.0070.00416.88
8.0.170.0070.00316.94
8.0.160.0040.00716.84
8.0.150.0110.00016.56
8.0.140.0110.00416.45
8.0.130.0100.00316.61
8.0.120.0130.00316.44
8.0.110.0050.00916.08
8.0.100.0120.00016.23
8.0.90.0050.00416.48
8.0.80.0070.00716.50
8.0.70.0100.00516.54
8.0.60.0050.00815.94
8.0.50.0080.00416.65
8.0.30.0030.01016.58
8.0.20.0070.00416.27
8.0.10.0040.00916.52
7.4.300.0040.00416.48
7.4.290.0190.00016.30
7.4.280.0160.00416.40
7.4.270.0140.00616.03
7.4.260.0080.00515.96
7.4.250.0050.00516.14
7.4.240.0060.01016.05
7.4.230.0110.00716.00
7.4.220.0070.00416.00
7.4.210.0040.00815.98
7.4.200.0090.00515.70
7.4.190.0140.00315.83
7.4.180.0090.00516.07
7.4.160.0050.00516.01
7.4.150.0100.00315.86
7.4.140.0100.00315.94
7.4.130.0110.00015.93
7.4.120.0120.00015.89
7.4.110.0080.00415.91
7.4.100.0070.00715.90
7.4.90.0000.01615.63
7.4.80.0090.00315.84
7.4.70.0150.00015.56
7.4.60.0080.00416.02
7.4.50.0080.00415.66
7.4.40.0040.00815.76
7.4.30.0070.00415.88
7.4.20.0070.00715.59
7.4.10.0090.00416.01
7.4.00.0100.00315.84

preferences:
47.83 ms | 403 KiB | 5 Q