3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Provides dependency injection friendly methods for serialization. */ trait DependencySerializationTrait { /** * An array of service IDs keyed by property name used for serialization. * * @var array */ // phpcs:ignore Drupal.Classes.PropertyDeclaration protected $_serviceIds = []; /** * An array of entity type IDs keyed by the property name of their storages. * * @var array */ // phpcs:ignore Drupal.Classes.PropertyDeclaration protected $_entityStorages = []; /** * {@inheritdoc} */ public function __sleep() { $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() { } } class A { use DependencySerializationTrait; private int $a = 1; 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); } protected function foo() { return $this->a; } } class B extends A { private int $a = 42; private int $b = 2; public function bar() { return $this->foo(); } public function baz() { return $this->a; } } $b = new B(); $b->doit(); echo PHP_EOL; echo "Before serialize:" . PHP_EOL; echo $b->bar() . PHP_EOL; echo $b->baz() . PHP_EOL; $c = unserialize(serialize($b)); echo "After serialize:" . PHP_EOL; echo $c->bar() . PHP_EOL; echo $b->baz() . 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.0100.01019.66
8.4.10.0160.00319.43
8.3.150.0040.00417.23
8.3.140.0030.00516.92
8.3.130.0070.00018.53
8.3.120.0090.00619.06
8.3.110.0040.00420.94
8.3.100.0000.00816.53
8.3.90.0120.00826.77
8.3.80.0000.00918.55
8.3.70.0070.00718.30
8.3.60.0430.01225.92
8.3.50.0100.01425.92
8.3.40.0260.01625.92
8.3.30.0420.00325.92
8.3.20.0320.01625.92
8.3.10.0380.01025.92
8.3.00.0440.00725.92
8.2.260.0030.00617.47
8.2.250.0080.00016.70
8.2.240.0030.00617.27
8.2.230.0040.00422.58
8.2.220.0100.01024.06
8.2.210.0050.00326.77
8.2.200.0060.00316.75
8.2.190.0090.00618.25
8.2.180.0340.01725.92
8.2.170.0430.01125.92
8.2.160.0380.01025.92
8.2.150.0280.00625.92
8.2.140.0340.00825.92
8.2.130.0320.01025.92
8.2.120.0350.00725.92
8.2.110.0340.00925.92
8.2.100.0390.00325.92
8.2.90.0380.00925.92
8.2.80.0350.01325.92
8.2.70.0410.00725.92
8.2.60.0330.01325.92
8.2.50.0410.01625.92
8.2.40.0540.00325.92
8.2.30.0370.01525.92
8.2.20.0420.00625.92
8.2.10.0380.01025.92
8.2.00.0360.01225.92
8.1.310.0140.00318.53
8.1.300.0070.00316.38
8.1.290.0040.00730.84
8.1.280.0320.01125.92
8.1.270.0320.01825.92
8.1.260.0420.00625.92
8.1.250.0330.01625.92
8.1.240.0360.00725.92
8.1.230.0330.00725.92
8.1.220.0320.00625.92
8.1.210.0290.01425.92
8.1.200.0340.00325.92
8.1.190.0270.01225.92
8.1.180.0330.00425.92
8.1.170.0310.01225.92
8.1.160.0280.01125.92
8.1.150.0320.01025.92
8.1.140.0330.00425.92
8.1.130.0350.00825.92
8.1.120.0350.00825.92
8.1.110.0350.00825.92
8.1.100.0310.01125.92
8.1.90.0280.01625.92
8.1.80.0370.00625.92
8.1.70.0410.00325.92
8.1.60.0470.01025.92
8.1.50.0480.01125.92
8.1.40.0490.00025.92
8.1.30.0390.00425.92
8.1.20.0390.00625.92
8.1.10.0370.01025.92
8.1.00.0440.00325.92

preferences:
43.02 ms | 403 KiB | 5 Q