3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Provides dependency injection friendly methods for serialization. */ trait DependencySerializationTrait { /** * {@inheritdoc} */ public function __sleep() { echo "hydrating " . $this::class . PHP_EOL; $closure = \Closure::bind(static function ($class) { return get_object_vars($class); }, NULL, $this); $vars = $closure($this); return array_keys($vars); } /** * {@inheritdoc} */ #[\ReturnTypeWillChange] public function __wakeup() { echo "dehydrating " . $this::class . PHP_EOL; } } trait dumper { public function doIt() { print "get_object_vars()\n"; print_r(get_object_vars($this)); $closure = \Closure::bind(static function ($class) { return get_object_vars($class); }, NULL, $this); $vars = $closure($this); print "\n\nClosure\n"; print_r($vars); } } class A { use dumper; use DependencySerializationTrait; private int $a = 1; public function echoA() { echo $this::class . "::" . __METHOD__ . ":" . $this->a . PHP_EOL; } } class B extends A { } class C extends B { use dumper; private int $a = 2; public function scopeCechoA() { echo $this::class . "::" . __METHOD__ . ":" . $this->a . PHP_EOL; } } class D extends B { use DependencySerializationTrait; private int $a = 3; public function scopeDechoA() { echo $this::class . "::" . __METHOD__ . ":" . $this->a . PHP_EOL; } } print "Class A\n"; (new A())->doit(); print "\n\nClass B\n"; $b = new B(); ($b)->doit(); print "\n\nClass C\n"; $c = new C(); ($c)->doit(); print "\n\nClass D\n"; $d = new D(); ($d)->doit(); echo PHP_EOL . PHP_EOL; echo ">>>>>>>>" . PHP_EOL; echo "Before B got serialized/deserialized:" . PHP_EOL; $b->echoA(); $b2 = unserialize(serialize($b)); echo "After B got serialized/deserialized:" . PHP_EOL; $b2->echoA(); echo "<<<<<<<<" . PHP_EOL; echo PHP_EOL . PHP_EOL; echo ">>>>>>>>" . PHP_EOL; echo "Before C got serialized/deserialized:" . PHP_EOL; $c->echoA(); $c->scopeCechoA(); $c2 = unserialize(serialize($c)); echo "After C got serialized/deserialized:" . PHP_EOL; $c2->echoA(); $c2->scopeCechoA(); echo "<<<<<<<<" . PHP_EOL; echo PHP_EOL . PHP_EOL; echo ">>>>>>>>" . PHP_EOL; echo "Before D got serialized/deserialized:" . PHP_EOL; $d->echoA(); $d->scopeDechoA(); $d2 = unserialize(serialize($d)); echo "After D got serialized/deserialized:" . PHP_EOL; $d2->echoA(); $d2->scopeDechoA(); echo "<<<<<<<<" . 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.20.0170.00319.77
8.4.10.0080.00019.15
8.3.150.0040.01417.23
8.3.140.0000.00816.45
8.3.130.0060.00318.60
8.3.120.0030.00520.50
8.3.110.0070.01120.94
8.3.100.0060.00324.06
8.3.90.0100.00626.77
8.3.80.0040.00718.18
8.3.70.0170.00718.06
8.3.60.0430.01125.92
8.3.50.0100.01325.92
8.3.40.0250.01925.92
8.3.30.0250.01825.92
8.3.20.0420.00625.92
8.3.10.0480.00625.92
8.3.00.0400.01125.92
8.2.260.0160.00416.81
8.2.250.0040.00418.46
8.2.240.0080.00317.55
8.2.230.0050.00522.58
8.2.220.0000.00837.54
8.2.210.0070.00026.77
8.2.200.0030.00616.75
8.2.190.0180.00316.63
8.2.180.0420.00625.92
8.2.170.0440.00925.92
8.2.160.0320.01425.92
8.2.150.0320.01025.92
8.2.140.0330.01225.92
8.2.130.0320.01125.92
8.2.120.0360.01425.92
8.2.110.0390.01125.92
8.2.100.0370.01425.92
8.2.90.0330.01125.92
8.2.80.0470.00025.92
8.2.70.0420.00425.92
8.2.60.0330.01025.92
8.2.50.0280.01925.92
8.2.40.0400.00325.92
8.2.30.0350.01125.92
8.2.20.0430.00425.92
8.2.10.0320.01425.92
8.2.00.0370.01125.92
8.1.310.0110.00716.80
8.1.300.0050.00320.19
8.1.290.0070.00330.84
8.1.280.0360.00725.92
8.1.270.0330.01225.92
8.1.260.0320.01325.92
8.1.250.0360.01025.92
8.1.240.0260.01325.92
8.1.230.0210.01625.92
8.1.220.0410.00725.92
8.1.210.0390.00825.92
8.1.200.0350.00925.92
8.1.190.0350.00825.92
8.1.180.0260.01225.92
8.1.170.0410.00325.92
8.1.160.0400.00325.92
8.1.150.0320.00625.92
8.1.140.0270.01225.92
8.1.130.0330.01325.92
8.1.120.0260.01125.92
8.1.110.0240.01225.92
8.1.100.0270.01025.92
8.1.90.0290.00825.92
8.1.80.0290.01325.92
8.1.70.0360.00625.92
8.1.60.0350.00825.92
8.1.50.0370.00925.92
8.1.40.0370.00925.92
8.1.30.0330.01325.92
8.1.20.0380.00025.92
8.1.10.0320.01125.92
8.1.00.0360.01325.92

preferences:
41.13 ms | 403 KiB | 5 Q