3v4l.org

run code in 300+ PHP versions simultaneously
<?php function hasValues(iterable &$value): bool { if (is_array($value)) { return (bool)$value; } if ($value instanceof \Iterator) { return $value->valid(); } $value = $value->getIterator(); return hasValues($value); } $weakMap = new WeakMap(); $x = new stdClass(); $y = new stdClass(); $weakMap[$x] = 'x'; $weakMap[$y] = 'y'; $data = [ [1, 2, 3], [], (fn () => yield from [1, 2, 3])(), (fn () => yield from [])(), new ArrayIterator([1, 2, 3]), new ArrayIterator([]), $weakMap, new WeakMap(), new RecursiveIteratorIterator(new RecursiveDirectoryIterator('/tmp', RecursiveDirectoryIterator::SKIP_DOTS)), ]; foreach ($data as $d) { print_r([ 'value' => $d, 'hasValues' => var_export($hasValues = hasValues($d), true), // Once a generator is checked and does not have any values we can't attempt to iterate it anymore. 'values' => $hasValues ? (is_array($d) ? $d : iterator_to_array($d, false)) : 'null', ]); }

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.0130.00724.16
8.4.110.0130.00819.07
8.4.100.0050.00418.93
8.4.90.0070.00120.53
8.4.80.0120.00519.14
8.4.70.0080.00119.38
8.4.60.0080.01318.86
8.4.50.0120.00820.51
8.4.40.0130.00718.75
8.4.30.0080.00019.06
8.4.20.0130.00719.43
8.4.10.0040.00419.54
8.3.250.0110.00917.13
8.3.240.0090.01017.33
8.3.230.0110.01016.47
8.3.220.0030.00419.16
8.3.210.0110.00718.47
8.3.200.0060.00216.61
8.3.190.0100.01017.28
8.3.180.0120.00718.63
8.3.170.0070.01120.71
8.3.160.0100.01017.31
8.3.150.0120.00417.48
8.3.140.0130.00616.71
8.3.130.0030.00618.38
8.3.120.0080.00020.68
8.3.110.0090.00016.90
8.3.100.0060.00324.06
8.3.90.0040.00426.77
8.3.80.0060.00319.36
8.3.70.0000.01516.88
8.3.60.0350.00725.92
8.3.50.0130.00325.92
8.3.40.0160.01325.92
8.3.30.0210.00825.92
8.3.20.0230.00825.92
8.3.10.0240.00725.92
8.3.00.0340.00025.92
8.2.290.0130.00620.36
8.2.280.0100.00818.37
8.2.270.0110.00417.39
8.2.260.0090.00916.80
8.2.250.0030.00518.49
8.2.240.0060.00318.94
8.2.230.0060.00320.94
8.2.220.0030.00637.54
8.2.210.0040.00426.77
8.2.200.0060.00318.88
8.2.190.0090.00916.58
8.2.180.0230.00825.92
8.2.170.0360.00025.92
8.2.160.0240.01225.92
8.2.150.0350.00025.92
8.2.140.0340.00925.92
8.2.130.0290.00725.92
8.2.120.0290.00625.92
8.2.110.0350.00025.92
8.2.100.0220.01625.92
8.2.90.0330.00025.92
8.2.80.0340.00025.92
8.2.70.0290.00925.92
8.2.60.0230.01125.92
8.2.50.0210.01225.92
8.2.40.0200.01125.92
8.2.30.0290.00325.92
8.2.20.0060.01025.92
8.2.10.0240.01025.92
8.2.00.0290.00925.92
8.1.330.0120.00922.04
8.1.320.0140.00816.40
8.1.310.0050.00316.97
8.1.300.0130.00620.15
8.1.290.0060.00330.84
8.1.280.0180.00025.92
8.1.270.0250.00825.92
8.1.260.0330.00325.92
8.1.250.0290.00625.92
8.1.240.0270.00325.92
8.1.230.0300.00325.92
8.1.220.0230.00625.92
8.1.210.0260.00325.92
8.1.200.0190.01225.92
8.1.190.0260.00425.92
8.1.180.0240.00625.92
8.1.170.0230.00725.92
8.1.160.0200.01125.92
8.1.150.0220.00725.92
8.1.140.0230.00625.92
8.1.130.0170.01325.92
8.1.120.0260.00525.92
8.1.110.0200.00925.92
8.1.100.0270.00325.92
8.1.90.0270.01025.92
8.1.80.0280.00625.92
8.1.70.0320.00325.92
8.1.60.0180.01525.92
8.1.50.0260.00825.92
8.1.40.0280.00725.92
8.1.30.0200.01325.92
8.1.20.0210.01125.92
8.1.10.0270.01225.92
8.1.00.0260.00625.92

preferences:
52.03 ms | 403 KiB | 5 Q