3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Book { protected $title; protected $author; protected $genres; public function __construct() { $this->genres = new ArrayObject(); } public function addGenre($genre) { $this->genres[] = $genre; return $this; } public function getGenres() { return $this->genres; } public function setAuthor(Person $author) { $this->author = $author; return $this; } public function getAuthor() { return $this->author; } public function setTitle($title) { $this->title = $title; return $this; } public function getTitle() { return $this->title; } } class Person { protected $firstName; protected $lastName; public function setFirstName($firstName) { $this->firstName = $firstName; return $this; } public function getFirstName() { return $this->firstName; } public function setLastName($lastName) { $this->lastName = $lastName; return $this; } public function getLastName() { return $this->lastName; } } interface Hydrator { public function hydrate($object, array $data); public function extract($object); } class ReflectionHydrator implements Hydrator { public function hydrate($object, array $data) { $reflection = new ClassReflection($object); $transform = function ($key) { return 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))); }; foreach ($reflection->getMethod() as $method) { if (!$method->isPublic() || 0 !== strpos($method->getName(), 'set')) { continue; } $field = lcfirst(substr($method->getName(), 3)); // @todo } } public function extract($object) { $reflection = new ClassReflection($object); $transform = function ($key) { return '_' . strtolower(array_shift($key)); }; $data = array(); foreach ($reflection->getMethods() as $method) { if (!$method->isPublic() || 0 !== strpos($method->getName(), 'get')) { continue; } $field = lcfirst(substr($method->getName(), 3)); $normalized = preg_replace_callback('/([A-Z])/', $transform, $field); $data[$normalized] = $method->invoke(); } return $array; } } class DryReflectionHydrator implements Hydrator { public function extract($object) { $transform = function ($key) { return '_' . strtolower(array_shift($key)); }; $data = array(); // Process get methods $this->processMethods('get', function ($field, MethodReflection $method) use (&$data, $transform) { $normalized = preg_replace_callback('/([A-Z])/', $transform, $field); $data[$normalized] = $method->invoke(); }); return $data; } public function hydrate($object, array $data) { $transform = function ($key) { return 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))); }; $this->processMethods('set', function($field, MethodReflection $method) use ($data, $transform) { $method->invoke(null, $data[$transform($field)]); }); } protected function processMethods($prefix, $callback) { $reflection = new ClassReflection($object); foreach ($reflection->getMethods() as $method) { if (!$method->isPublic() || 0 !== strpos($method->getName(), $prefix)) { continue; } $field = lcfirst(substr($method->getName(), strlen($prefix))); $callback($field, $method); } } } $book = new Book(); $book->setTitle('Harry potter'); $book->addGenre('Drama')->addGenre('Nosense'); $hydrator = new ReflectionHydrator(); var_dump($hydrator->extract($book));

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.60.0190.00316.75
8.3.50.0110.01121.99
8.3.40.0150.00019.02
8.3.30.0030.01219.18
8.3.20.0120.00620.33
8.3.10.0090.00022.14
8.3.00.0160.00322.51
8.2.180.0070.01416.88
8.2.170.0070.00722.96
8.2.160.0140.00720.94
8.2.150.0050.00324.18
8.2.140.0070.00424.66
8.2.130.0090.00026.16
8.2.120.0090.00619.13
8.2.110.0050.00521.00
8.2.100.0060.00619.83
8.2.90.0000.00819.46
8.2.80.0080.00018.00
8.2.70.0040.00417.75
8.2.60.0040.00418.17
8.2.50.0080.00018.07
8.2.40.0030.00619.95
8.2.30.0060.00318.21
8.2.20.0040.00417.78
8.2.10.0050.00319.58
8.2.00.0030.00517.95
8.1.280.0070.01125.92
8.1.270.0130.00622.03
8.1.260.0050.00526.35
8.1.250.0060.01228.09
8.1.240.0060.00322.54
8.1.230.0060.00617.95
8.1.220.0040.00417.91
8.1.210.0040.00418.77
8.1.200.0030.00717.48
8.1.190.0090.00017.35
8.1.180.0000.00818.10
8.1.170.0000.01020.30
8.1.160.0080.00018.98
8.1.150.0000.00818.61
8.1.140.0040.00417.46
8.1.130.0000.00717.94
8.1.120.0000.00717.58
8.1.110.0000.00717.53
8.1.100.0070.00017.50
8.1.90.0030.00617.45
8.1.80.0000.00717.49
8.1.70.0040.00417.56
8.1.60.0030.00617.56
8.1.50.0030.00617.55
8.1.40.0040.00417.45
8.1.30.0040.00417.76
8.1.20.0060.00317.77
8.1.10.0000.00817.56
8.1.00.0040.00417.57
8.0.300.0040.00418.77
8.0.290.0040.00416.88
8.0.280.0070.00018.53
8.0.270.0070.00017.28
8.0.260.0070.00016.98
8.0.250.0070.00017.11
8.0.240.0040.00417.07
8.0.230.0030.00417.08
8.0.220.0000.00716.91
8.0.210.0080.00016.95
8.0.200.0030.00316.96
8.0.190.0080.00017.03
8.0.180.0000.00717.12
8.0.170.0080.00017.02
8.0.160.0000.00817.09
8.0.150.0050.00317.03
8.0.140.0050.00316.97
8.0.130.0000.00513.40
8.0.120.0000.00816.91
8.0.110.0000.00817.11
8.0.100.0040.00417.02
8.0.90.0000.00816.92
8.0.80.0030.01317.02
8.0.70.0040.00416.95
8.0.60.0000.00716.90
8.0.50.0000.00717.06
8.0.30.0090.01217.33
8.0.20.0060.01417.40
8.0.10.0040.00417.04
8.0.00.0160.00316.76
7.4.330.0030.00315.16
7.4.320.0000.00616.60
7.4.300.0030.00316.55
7.4.290.0070.00016.61
7.4.280.0080.00016.59
7.4.270.0040.00416.68
7.4.260.0040.00416.61
7.4.250.0080.00016.66
7.4.240.0020.00516.70
7.4.230.0030.00316.33
7.4.220.0110.00716.73
7.4.210.0090.00716.60
7.4.200.0070.00016.79
7.4.190.0000.00716.72
7.4.160.0130.00316.68
7.4.150.0150.00917.40
7.4.140.0150.00317.86
7.4.130.0120.01116.67
7.4.120.0100.00816.67
7.4.110.0070.01016.69
7.4.100.0040.01616.53
7.4.90.0070.01016.75
7.4.80.0100.01019.39
7.4.70.0100.00716.64
7.4.60.0080.00816.61
7.4.50.0040.00416.51
7.4.40.0100.00322.77
7.4.30.0090.00916.67
7.4.10.0070.01015.07
7.4.00.0050.00915.24
7.3.330.0000.00513.53
7.3.320.0000.00513.43
7.3.310.0030.00316.38
7.3.300.0070.00016.36
7.3.290.0070.01416.37
7.3.280.0090.00716.45
7.3.270.0080.00817.40
7.3.260.0090.00916.48
7.3.250.0150.00516.47
7.3.240.0090.01416.60
7.3.230.0120.00616.50
7.3.210.0120.00616.59
7.3.200.0090.01316.57
7.3.190.0170.00716.70
7.3.180.0150.00916.40
7.3.170.0030.01916.64
7.3.160.0030.01216.46
7.3.130.0090.00914.98
7.3.120.0030.01314.85
7.3.110.0090.00915.11
7.3.100.0030.01015.09
7.3.90.0030.01015.00
7.3.80.0130.00615.04
7.3.70.0030.01314.81
7.3.60.0100.00314.83
7.3.50.0090.00914.91
7.3.40.0000.01415.00
7.3.30.0040.01214.99
7.3.20.0060.00916.76
7.3.10.0030.01016.83
7.3.00.0070.00716.63
7.2.330.0000.01716.95
7.2.320.0180.00416.91
7.2.310.0110.00716.39
7.2.300.0070.01116.80
7.2.290.0050.01116.95
7.2.260.0080.01115.23
7.2.250.0100.00715.36
7.2.240.0030.01115.13
7.2.230.0070.01015.37
7.2.220.0100.00615.25
7.2.210.0070.01014.94
7.2.200.0040.01414.89
7.2.190.0120.00315.22
7.2.180.0030.01315.31
7.2.170.0000.01615.11
7.2.160.0030.01015.10
7.2.150.0060.00916.92
7.2.140.0060.00316.94
7.2.130.0070.00716.92
7.2.120.0080.00416.66
7.2.110.0000.01516.89
7.2.100.0000.01417.08
7.2.90.0130.00316.71
7.2.80.0070.00716.92
7.2.70.0040.00716.95
7.2.60.0070.00416.80
7.2.50.0000.01116.74
7.2.40.0070.01116.95
7.2.30.0070.00716.95
7.2.20.0000.01516.69
7.2.10.0090.00616.97
7.2.00.0070.00718.22
7.1.330.0030.00915.86
7.1.320.0100.01015.94
7.1.310.0100.00315.88
7.1.300.0060.00915.92
7.1.290.0030.01015.75
7.1.280.0040.00815.78
7.1.270.0000.01315.60
7.1.260.0070.00315.80
7.1.250.0090.00315.70
7.1.240.0030.01015.72
7.1.230.0060.00915.71
7.1.220.0030.01015.81
7.1.210.0060.00915.40
7.1.200.0080.00515.68
7.1.190.0040.00815.83
7.1.180.0000.01815.88
7.1.170.0100.00615.40
7.1.160.0050.00815.75
7.1.150.0040.00515.54
7.1.140.0090.00615.83
7.1.130.0030.00615.63
7.1.120.0070.00715.87
7.1.110.0040.00415.74
7.1.100.0020.01016.97
7.1.90.0090.00615.71
7.1.80.0120.00615.97
7.1.70.0070.00816.42
7.1.60.0030.01217.79
7.1.50.0020.01216.40
7.1.40.0000.01815.88
7.1.30.0030.01015.84
7.1.20.0100.00015.73
7.1.10.0060.00315.88
7.1.00.0100.03819.13
7.0.330.0030.00815.55
7.0.320.0090.00615.39
7.0.310.0080.00415.41
7.0.300.0090.00315.59
7.0.290.0070.01015.38
7.0.280.0070.00715.41
7.0.270.0080.00415.20
7.0.260.0060.00615.59
7.0.250.0060.00615.45
7.0.240.0090.00615.55
7.0.230.0080.00415.50
7.0.220.0110.00715.32
7.0.210.0040.00815.24
7.0.200.0060.00516.14
7.0.190.0000.01515.47
7.0.180.0040.01115.52
7.0.170.0000.01715.48
7.0.160.0060.00615.33
7.0.150.0090.00615.31
7.0.140.0070.04018.63
7.0.130.0030.01415.53
7.0.120.0090.00615.14
7.0.110.0080.00315.31
7.0.100.0050.03618.65
7.0.90.0070.02818.53
7.0.80.0020.03918.65
7.0.70.0030.04518.60
7.0.60.0070.04218.54
7.0.50.0040.04618.83
7.0.40.0040.03216.72
7.0.30.0030.04316.88
7.0.20.0020.04516.81
7.0.10.0030.04116.86
7.0.00.0050.04416.82
5.6.400.0000.01014.79
5.6.390.0000.01414.83
5.6.380.0060.01214.76
5.6.370.0000.01414.77
5.6.360.0140.00414.63
5.6.350.0100.00714.65
5.6.340.0040.01114.59
5.6.330.0070.00714.80
5.6.320.0000.01514.23
5.6.310.0000.00914.44
5.6.300.0090.00614.30
5.6.290.0090.00614.29
5.6.280.0040.04417.78
5.6.270.0070.00714.87
5.6.260.0100.00314.77
5.6.250.0060.04417.66
5.6.240.0020.04617.47
5.6.230.0090.02517.46
5.6.220.0080.04117.48
5.6.210.0030.02917.52
5.6.200.0040.05717.80
5.6.190.0130.04017.82
5.6.180.0100.03017.85
5.6.170.0050.04317.75
5.6.160.0030.04717.84
5.6.150.0060.04617.66
5.6.140.0030.04717.89
5.6.130.0050.04517.76
5.6.120.0070.04517.83
5.6.110.0120.04017.68
5.6.100.0050.04317.75
5.6.90.0080.04917.80
5.6.80.0100.04017.35
5.6.70.0050.03717.49
5.6.60.0070.04117.42
5.6.50.0050.03817.29
5.6.40.0040.03917.27
5.6.30.0020.02917.32
5.6.20.0110.03617.43
5.6.10.0080.04217.48
5.6.00.0070.04217.38
5.5.380.0050.04317.52
5.5.370.0010.04817.41
5.5.360.0050.02917.42
5.5.350.0050.03417.38
5.5.340.0090.04217.78
5.5.330.0050.04517.52
5.5.320.0050.04317.66
5.5.310.0070.04117.73
5.5.300.0050.04717.63
5.5.290.0050.04717.54
5.5.280.0030.04817.56
5.5.270.0050.04517.59
5.5.260.0120.04817.77
5.5.250.0030.04917.53
5.5.240.0060.04317.27
5.5.230.0050.04417.25
5.5.220.0040.04417.33
5.5.210.0050.04417.36
5.5.200.0050.04017.15
5.5.190.0020.04517.34
5.5.180.0030.04217.30
5.5.170.0000.01414.46
5.5.160.0060.04417.25
5.5.150.0060.02017.27
5.5.140.0030.04517.39
5.5.130.0040.02417.17
5.5.120.0040.02217.44
5.5.110.0070.03817.41
5.5.100.0000.04617.13
5.5.90.0100.03917.27
5.5.80.0030.04617.31
5.5.70.0100.02517.04
5.5.60.0030.04317.24
5.5.50.0010.04117.13
5.5.40.0020.04917.20
5.5.30.0070.04317.37
5.5.20.0020.04617.20
5.5.10.0050.04317.27
5.5.00.0030.03717.26
5.4.450.0100.03816.35
5.4.440.0030.02816.31
5.4.430.0020.02816.30
5.4.420.0090.03016.40
5.4.410.0100.03716.14
5.4.400.0000.04216.16
5.4.390.0000.04816.21
5.4.380.0050.02816.14
5.4.370.0020.03216.21
5.4.360.0030.04316.21
5.4.350.0030.04516.14
5.4.340.0100.03516.14
5.4.330.0040.00413.25
5.4.320.0050.03016.05
5.4.310.0020.02516.14
5.4.300.0050.04016.19
5.4.290.0020.02916.14
5.4.280.0040.02016.19
5.4.270.0050.04116.09
5.4.260.0050.03816.19
5.4.250.0020.02516.13
5.4.240.0000.04416.14
5.4.230.0050.03716.14
5.4.220.0070.04316.20
5.4.210.0070.03916.18
5.4.200.0030.04116.20
5.4.190.0070.04016.24
5.4.180.0020.04016.14
5.4.170.0050.03716.24
5.4.160.0020.04216.17
5.4.150.0000.03616.14
5.4.140.0060.03514.84
5.4.130.0050.03314.90
5.4.120.0030.03814.85
5.4.110.0050.02214.90
5.4.100.0060.03614.81
5.4.90.0100.02314.90
5.4.80.0020.03914.82
5.4.70.0050.01814.85
5.4.60.0070.02214.89
5.4.50.0070.02814.88
5.4.40.0040.02214.81
5.4.30.0040.02514.87
5.4.20.0020.02514.81
5.4.10.0020.02514.80
5.4.00.0000.02714.60
5.3.290.0060.01814.02
5.3.280.0040.03213.94
5.3.270.0030.03514.03
5.3.260.0020.03213.99
5.3.250.0050.03713.97
5.3.240.0020.02813.95
5.3.230.0030.03713.97
5.3.220.0030.04213.95
5.3.210.0030.04113.93
5.3.200.0030.04313.92
5.3.190.0060.03514.01
5.3.180.0020.04113.97
5.3.170.0020.02513.98
5.3.160.0020.02713.94
5.3.150.0120.02513.96
5.3.140.0000.02413.91
5.3.130.0020.02313.93
5.3.120.0050.01913.89
5.3.110.0020.02513.97
5.3.100.0040.02613.73
5.3.90.0050.02213.69
5.3.80.0070.01913.63
5.3.70.0000.02513.63
5.3.60.0020.02513.61
5.3.50.0000.02313.66
5.3.40.0060.02613.64
5.3.30.0020.02513.68
5.3.20.0030.02613.47
5.3.10.0050.02513.49
5.3.00.0000.02213.54

preferences:
47.13 ms | 401 KiB | 5 Q