3v4l.org

run code in 300+ PHP versions simultaneously
<?php class test{ protected $id; protected $name; public function getId(){ return $this->id; } public function setId($id){ $this->id = $id; return $this; } public function getName(){ return $this->name; } public function setName($name){ $this->name = $name; return $this; } } class AbstractDbToMapper { /** * @var array */ protected $fields = [ 'new_spec_name' => 'name', 'object_id' => 'id' ]; /** * @param $data * * @return mixed */ public function mapFromDbData($data, $object) { $arrayKeys = array_keys($data); if(empty($arrayKeys)){ return $object; } foreach ($arrayKeys as $key){ if(empty($key)){ continue; } if(!array_key_exists($key,$this->fields)){ continue; } $field = $this->fields[$key]; $method = sprintf('set%s', ucfirst($field)); if(!method_exists($object,$method)){ continue; } call_user_func([$object, $method,$data[$field]]); } return $object; } /** * @param $object * * @return mixed */ public function mapToDbData($object) { $objectFields = array_map( function ($field) { return lcfirst(substr($field, 3)); }, preg_grep('/^get/', get_class_methods($object)) ); $resultArray = []; foreach ($objectFields as $field) { if (!in_array($field, $this->fields)) { continue; } $key = array_search($field,$this->fields); if (empty($key)) { continue; } $method = sprintf('get%s', ucfirst($field)); $resultArray[$key] = call_user_func([$object, $method]); } return $resultArray; } } $array = [ 'object_id' => 4, 'new_spec_name' => 'Супер пупер имя', ]; $test = new test(); $mapper = new AbstractDbToMapper(); var_dump($mapper->mapFromDbData($array,$test)); var_dump($mapper->mapToDbData($test));

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.0130.01018.52
8.3.50.0040.01118.13
8.3.40.0070.00718.89
8.3.30.0110.00418.84
8.3.20.0120.00319.15
8.3.10.0080.00020.86
8.3.00.0000.00823.66
8.2.180.0170.00018.54
8.2.170.0100.00722.96
8.2.160.0070.00719.45
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0050.00321.07
8.2.120.0180.00026.35
8.2.110.0040.00722.30
8.2.100.0080.00419.70
8.2.90.0000.00919.17
8.2.80.0050.00317.97
8.2.70.0000.00817.93
8.2.60.0040.00417.93
8.2.50.0050.00318.10
8.2.40.0000.00919.42
8.2.30.0040.00419.40
8.2.20.0040.00418.09
8.2.10.0000.00718.25
8.2.00.0020.00519.52
8.1.280.0090.00625.92
8.1.270.0040.00422.05
8.1.260.0000.00826.35
8.1.250.0050.00228.09
8.1.240.0030.00622.24
8.1.230.0070.00422.09
8.1.220.0040.00417.78
8.1.210.0040.00418.77
8.1.200.0070.00317.48
8.1.190.0040.00417.36
8.1.180.0000.00818.10
8.1.170.0000.01120.27
8.1.160.0070.00018.93
8.1.150.0000.00718.99
8.1.140.0020.00517.76
8.1.130.0000.00719.04
8.1.120.0080.00017.55
8.1.110.0050.00317.44
8.1.100.0030.00417.41
8.1.90.0040.00417.47
8.1.80.0000.00717.39
8.1.70.0090.00017.54
8.1.60.0100.00017.54
8.1.50.0000.00817.51
8.1.40.0080.00017.56
8.1.30.0040.00417.59
8.1.20.0100.00017.72
8.1.10.0030.00617.64
8.1.00.0000.00917.54
8.0.300.0050.00218.77
8.0.290.0060.00316.59
8.0.280.0030.00318.49
8.0.270.0070.00017.20
8.0.260.0030.00517.23
8.0.250.0000.00717.07
8.0.240.0080.00017.06
8.0.230.0070.00017.04
8.0.220.0000.00716.90
8.0.210.0040.00417.04
8.0.200.0030.00317.11
8.0.190.0030.00617.04
8.0.180.0000.00716.98
8.0.170.0000.00916.91
8.0.160.0070.00017.02
8.0.150.0090.00016.86
8.0.140.0000.00816.92
8.0.130.0000.00513.47
8.0.120.0000.00716.98
8.0.110.0000.00716.90
8.0.100.0000.00817.07
8.0.90.0040.00416.86
8.0.80.0130.00517.04
8.0.70.0050.00317.02
8.0.60.0000.00817.02
8.0.50.0070.00017.00
8.0.30.0110.00817.20
8.0.20.0100.01017.40
8.0.10.0050.00317.24
8.0.00.0120.00616.76
7.4.330.0090.00015.55
7.4.320.0000.00816.86
7.4.300.0000.00716.88
7.4.290.0000.00716.75
7.4.280.0000.00816.86
7.4.270.0000.00716.72
7.4.260.0050.00316.76
7.4.250.0080.00016.72
7.4.240.0030.00316.78
7.4.230.0030.00316.75
7.4.220.0030.00616.77
7.4.210.0090.00816.83
7.4.200.0040.00416.93
7.4.160.0070.01016.82
7.4.140.0120.00917.86
7.4.130.0110.00616.81
7.4.120.0110.00716.83
7.4.110.0120.00616.84
7.4.100.0070.01016.82
7.4.90.0100.01016.89
7.4.80.0040.01419.39
7.4.70.0060.01716.75
7.4.60.0070.01016.68
7.4.50.0040.01116.56
7.4.40.0090.00916.84
7.4.10.0070.01015.32
7.4.00.0100.00815.27
7.3.330.0000.00513.40
7.3.320.0030.00313.48
7.3.310.0050.00316.52
7.3.300.0030.00316.51
7.3.290.0030.00316.57
7.3.280.0130.00316.60
7.3.260.0130.00616.77
7.3.240.0090.01016.71
7.3.230.0180.00016.65
7.3.210.0090.00916.84
7.3.200.0060.01016.97
7.3.190.0080.00816.88
7.3.180.0090.00916.69
7.3.170.0070.01016.75
7.3.160.0110.01016.75
7.3.130.0150.00315.13
7.3.120.0030.01315.07
7.3.110.0100.00814.88
7.3.100.0050.00715.02
7.3.90.0020.01415.32
7.3.80.0050.00615.02
7.3.70.0070.00615.06
7.3.60.0080.00715.16
7.3.50.0050.01215.10
7.3.40.0030.00915.14
7.3.30.0090.00315.20
7.3.20.0090.00617.02
7.3.10.0030.00716.96
7.3.00.0040.01116.91
7.2.330.0060.01216.91
7.2.320.0060.01416.81
7.2.310.0170.02616.89
7.2.300.0060.01216.92
7.2.290.0200.00716.88
7.2.260.0030.01315.38
7.2.250.0060.01115.30
7.2.240.0090.00515.53
7.2.230.0010.01015.25
7.2.220.0050.01015.45
7.2.210.0050.01115.47
7.2.200.0040.01115.29
7.2.190.0080.00815.25
7.2.180.0060.00815.24
7.2.170.0070.00815.32
7.2.160.0030.01015.50
7.2.150.0060.01016.87
7.2.140.0030.01617.09
7.2.130.0040.01117.14
7.2.120.0040.01117.30
7.2.110.0060.01116.97
7.2.100.0040.01117.02
7.2.90.0030.01017.20
7.2.80.0110.00717.00
7.2.70.0290.00816.25
7.2.60.0280.00516.31
7.2.50.0260.00816.29
7.2.40.0270.00616.41
7.2.30.0250.00616.33
7.2.20.0270.00516.29
7.2.10.0350.00816.18
7.2.00.0220.01516.35
7.1.330.0050.00815.93
7.1.320.0050.00915.95
7.1.310.0050.00916.11
7.1.300.0050.01315.98
7.1.290.0090.00215.92
7.1.280.0070.00515.94
7.1.270.0060.00716.21
7.1.260.0080.00516.09
7.1.250.0000.01515.78
7.1.240.0000.01015.96
7.1.230.0060.01016.17
7.1.220.0070.01015.63
7.1.210.0030.00715.74
7.1.200.0070.00915.88
7.1.190.0040.00816.06
7.1.180.0030.01016.00
7.1.170.0230.00915.07
7.1.160.0270.00515.04
7.1.150.0220.01315.05
7.1.140.0350.00315.02
7.1.130.0250.00615.12
7.1.120.0270.00615.06
7.1.110.0280.00515.03
7.1.100.0540.00515.13
7.1.90.0380.01215.05
7.1.80.0310.00514.93
7.1.70.0360.00315.04
7.1.60.0430.00324.21
7.1.50.0410.01024.04
7.1.40.0550.01323.98
7.1.30.0420.01124.00
7.1.20.0440.01324.26
7.1.10.0350.00815.02
7.1.00.0290.00915.11
7.0.330.0030.01015.39
7.0.320.0070.00415.79
7.0.310.0000.01515.70
7.0.300.0070.00715.68
7.0.290.0040.00815.57
7.0.280.0040.00815.79
7.0.270.0070.00715.46
7.0.260.0110.00315.68
7.0.250.0080.00415.54
7.0.240.0080.00515.74
7.0.230.0070.01015.83
7.0.220.0100.00315.57
7.0.210.0060.00615.65
7.0.200.0090.00615.57
7.0.190.0070.00315.51
7.0.180.0070.00315.69
7.0.170.0070.00715.69
7.0.160.0070.00415.80
7.0.150.0000.01215.64
7.0.140.0040.00415.56
7.0.130.0000.01815.68
7.0.120.0110.00315.55
7.0.110.0100.00615.56
7.0.100.0070.00715.39
7.0.90.0060.00915.55
7.0.80.0060.01015.47
7.0.70.0040.00415.23
7.0.60.0000.01515.66
7.0.50.0030.01015.44
7.0.40.0030.01013.80
7.0.30.0040.00413.69
7.0.20.0060.00313.70
7.0.10.0030.00713.51
7.0.00.0000.01713.49
5.6.400.0090.00614.59
5.6.390.0000.00914.88
5.6.380.0070.00714.34
5.6.370.0070.01014.38
5.6.360.0040.00814.62
5.6.350.0060.00614.50
5.6.340.0000.01114.65
5.6.330.0070.00714.88
5.6.320.0000.01314.32
5.6.310.0070.00714.74
5.6.300.0000.01714.76
5.6.290.0030.01014.79
5.6.280.0070.00714.59
5.6.270.0070.00714.64
5.6.260.0060.00914.57
5.6.250.0030.00914.52
5.6.240.0000.01714.25
5.6.230.0030.00914.51
5.6.220.0030.01014.87
5.6.210.0000.00914.65
5.6.200.0040.01114.30
5.6.190.0000.00814.43
5.6.180.0060.00614.59
5.6.170.0000.01014.37
5.6.160.0040.01414.56
5.6.150.0000.01714.67
5.6.140.0060.00914.29
5.6.130.0120.00414.83
5.6.120.0090.00614.50
5.6.110.0070.00714.44
5.6.100.0080.00414.72
5.6.90.0060.00614.41
5.6.80.0070.00714.45
5.6.70.0030.01014.32
5.6.60.0040.01114.14
5.6.50.0030.01214.31
5.6.40.0000.01614.49
5.6.30.0070.00714.20
5.6.20.0000.01014.38
5.6.10.0060.00914.57
5.6.00.0070.01114.51

preferences:
60.96 ms | 400 KiB | 5 Q