3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ParentClass { private $property = 'parent private property'; } class C extends ParentClass { private $property = 'child private property'; } $object = new C(); // Using ReflectionProperty $refProperty = new ReflectionProperty(ParentClass::class, 'property'); $refProperty->setAccessible(true); $startReflection = microtime(true); $reflectionValue = $refProperty->getValue($object); $endReflection = microtime(true); // Using array casting $startArray = microtime(true); $arrayValue = (array)$object; $arrayValueDirect = $arrayValue["\0" . ParentClass::class . "\0" . 'property']; $endArray = microtime(true); echo "Reflection Value: $reflectionValue\n"; echo "Array Casting Value: $arrayValueDirect\n"; echo "Reflection Time: " . ($endReflection - $startReflection) . " seconds\n"; echo "Array Casting Time: " . ($endArray - $startArray) . " seconds\n"; // Using ReflectionProperty $refProperty = new ReflectionProperty(ParentClass::class, 'property'); $refProperty->setAccessible(true); $startReflection = microtime(true); $reflectionValue = $refProperty->getValue($object); $endReflection = microtime(true); // Using array casting $startArray = microtime(true); $arrayValue = (array)$object; $arrayValueDirect = $arrayValue["\0" . ParentClass::class . "\0" . 'property']; $endArray = microtime(true); echo "Reflection Value: $reflectionValue\n"; echo "Array Casting Value: $arrayValueDirect\n"; echo "Reflection Time: " . ($endReflection - $startReflection) . " seconds\n"; echo "Array Casting Time: " . ($endArray - $startArray) . " seconds\n";

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.3.130.0250.01117.14
8.3.120.0300.01216.53
8.3.110.0370.00716.27
8.3.100.0420.01716.24
8.3.90.0400.01216.72
8.3.80.0400.00716.41
8.3.70.0260.01516.76
8.3.60.0300.01016.43
8.3.50.0390.00616.60
8.3.40.0340.00617.27
8.3.30.0260.00717.39
8.3.20.0370.00717.21
8.3.10.0240.01717.26
8.3.00.0130.00519.30
8.2.250.0160.00917.53
8.2.240.0250.00016.41
8.2.230.0140.00716.23
8.2.220.0140.00416.37
8.2.210.0160.01016.70
8.2.200.0180.00516.40
8.2.190.0150.01116.47
8.2.180.0250.00716.46
8.2.170.0370.00717.72
8.2.160.0370.00417.50
8.2.150.0280.01417.67
8.2.140.0390.00317.24
8.2.130.0340.00817.64
8.2.120.0380.00417.57
8.2.110.0410.00017.38
8.2.100.0330.00717.53
8.2.90.0290.00817.44
8.2.80.0280.00017.53
8.2.70.0170.00817.53
8.2.60.0260.01117.71
8.2.50.0330.00017.54
8.2.40.0270.01417.47
8.2.30.0230.01517.45
8.2.20.0260.01117.58
8.2.10.0250.01617.54
8.2.00.0340.00317.59
8.1.300.0240.01216.21
8.1.290.0270.00516.18
8.1.280.0300.00616.18
8.1.270.0270.00817.33
8.1.260.0350.01317.33
8.1.250.0400.00417.40
8.1.240.0230.01317.32
8.1.230.0170.01317.24
8.1.220.0240.00617.20
8.1.210.0230.01317.18
8.1.200.0180.01416.85
8.1.190.0180.01117.18
8.1.180.0350.00316.98
8.1.170.0330.00317.13
8.1.160.0320.00817.00
8.1.150.0280.00917.36
8.1.140.0290.00717.13
8.1.130.0250.01117.30
8.1.120.0320.00417.35
8.1.110.0270.01016.96
8.1.100.0300.00717.43
8.1.90.0270.01417.15
8.1.80.0210.01517.21
8.1.70.0110.01117.30
8.1.60.0150.00916.99
8.1.50.0180.00017.40
8.1.40.0300.00717.18
8.1.30.0230.00917.46
8.1.20.0250.00717.15
8.1.10.0250.00617.28
8.1.00.0380.01117.05

preferences:
28.16 ms | 403 KiB | 5 Q