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($array); 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.0110.00718.30
8.3.50.0070.00718.07
8.3.40.0070.00718.68
8.3.30.0120.00318.81
8.3.20.0000.00918.93
8.3.10.0030.00519.27
8.3.00.0000.00823.66
8.2.180.0090.01218.42
8.2.170.0030.01422.96
8.2.160.0090.00619.04
8.2.150.0040.00424.18
8.2.140.0060.00324.66
8.2.130.0040.00421.18
8.2.120.0080.00026.35
8.2.110.0110.00022.07
8.2.100.0060.00619.64
8.2.90.0000.00819.07
8.2.80.0000.00817.97
8.2.70.0000.00817.91
8.2.60.0040.00417.93
8.2.50.0080.00018.10
8.2.40.0040.00419.32
8.2.30.0000.00719.24
8.2.20.0000.00718.04
8.2.10.0050.00218.11
8.2.00.0000.00719.45
8.1.280.0110.00425.92
8.1.270.0120.00423.96
8.1.260.0060.00926.35
8.1.250.0040.00428.09
8.1.240.0000.00922.20
8.1.230.0060.00621.98
8.1.220.0000.00817.74
8.1.210.0000.00818.77
8.1.200.0030.00617.23
8.1.190.0080.00017.22
8.1.180.0050.00318.10
8.1.170.0000.00918.51
8.1.160.0040.00418.87
8.1.150.0000.00818.88
8.1.140.0040.00417.64
8.1.130.0000.00720.78
8.1.120.0000.00817.35
8.1.110.0000.00717.34
8.1.100.0040.00417.33
8.1.90.0040.00417.35
8.1.80.0050.00317.34
8.1.70.0000.00817.45
8.1.60.0040.00417.62
8.1.50.0040.00417.43
8.1.40.0040.00417.45
8.1.30.0000.00817.77
8.1.20.0080.00317.57
8.1.10.0090.00017.63
8.1.00.0030.00617.45
8.0.300.0030.00518.77
8.0.290.0070.00416.75
8.0.280.0070.00018.54
8.0.270.0000.00717.17
8.0.260.0030.00317.23
8.0.250.0000.00817.00
8.0.240.0060.00317.00
8.0.230.0000.00716.96
8.0.220.0000.00716.99
8.0.210.0000.00716.94
8.0.200.0000.00816.88
8.0.190.0080.00017.01
8.0.180.0040.00416.93
8.0.170.0090.00016.84
8.0.160.0040.00416.88
8.0.150.0050.00216.77
8.0.140.0000.00816.89
8.0.130.0000.00613.38
8.0.120.0050.00316.80
8.0.110.0000.00716.88
8.0.100.0000.00716.93
8.0.90.0020.00517.01
8.0.80.0110.00616.93
8.0.70.0040.00417.05
8.0.60.0000.00817.05
8.0.50.0050.00216.95
8.0.30.0140.00317.30
8.0.20.0050.01317.40
8.0.10.0030.00516.85
8.0.00.0090.00916.72
7.4.330.0040.00415.55
7.4.320.0070.00016.63
7.4.300.0040.00416.85
7.4.290.0030.00316.67
7.4.280.0040.00416.65
7.4.270.0070.00016.91
7.4.260.0070.00016.64
7.4.250.0040.00416.71
7.4.240.0040.00416.87
7.4.230.0080.00016.61
7.4.220.0040.00416.88
7.4.210.0070.00816.84
7.4.200.0030.00316.84
7.4.160.0110.00516.81
7.4.140.0110.00717.86
7.4.130.0070.01016.85
7.4.120.0120.00816.76
7.4.110.0040.01416.89
7.4.100.0130.00816.85
7.4.90.0140.00616.80
7.4.80.0130.00919.39
7.4.70.0100.01016.91
7.4.60.0100.00716.77
7.4.50.0030.01016.74
7.4.40.0070.01016.84
7.4.00.0130.00315.47
7.3.330.0050.00013.48
7.3.320.0030.00313.62
7.3.310.0070.00016.73
7.3.300.0040.00416.57
7.3.290.0000.00816.62
7.3.280.0070.00716.58
7.3.260.0080.00916.79
7.3.240.0110.00916.79
7.3.230.0030.01616.59
7.3.210.0060.01416.69
7.3.200.0100.00616.65
7.3.190.0130.00616.79
7.3.180.0100.00716.92
7.3.170.0160.00016.59
7.3.160.0100.00616.80
7.2.330.0090.00916.98
7.2.320.0140.01017.01
7.2.310.0070.04016.95
7.2.300.0060.01216.96
7.2.290.0030.02316.90
7.2.70.0420.00915.33
7.2.60.0340.01215.18
7.2.50.0340.01215.21
7.2.40.0440.00615.20
7.2.30.0460.00315.36
7.2.20.0420.00715.30
7.2.10.0410.00915.38
7.2.00.0390.00715.51
7.1.200.0040.01116.04
7.1.170.0300.01613.82
7.1.160.0450.00713.95
7.1.150.0410.01014.25
7.1.140.0380.00914.32
7.1.130.0350.00913.95
7.1.120.0450.00614.09
7.1.110.0420.00314.22
7.1.100.1060.00714.11
7.1.90.0470.01013.91
7.1.80.0500.00314.06
7.1.70.0650.00614.05
7.1.60.0720.00732.24
7.1.50.0680.01332.11
7.1.40.0740.00632.07
7.1.30.0880.01032.06
7.1.20.0800.01032.23
7.1.10.0600.01013.77
7.1.00.0530.00014.23

preferences:
57.32 ms | 400 KiB | 5 Q