3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * created on 1.2.2008 */ class RootObj implements JsonSerializable { private $_data; public function __construct($data = null) { $this->_data = $data; } public function &__get($name) { return $this->_data[$name]; } public function __set($name, $value) { $this->_data[$name] = $value; } public function __isset($name) { return isset($this->_data[$name]); } public static function createObjectsFromArray($className, $array, $defaults = [], $idAsKey = false) { $results = []; foreach ($array as $data) { $result = new $className ($data); if ($idAsKey) { if (is_object($data) && isset($data->id)) { $results[$data->id] = $result; } else { $results[$data['id']] = $result; } } else { $results[] = $result; } foreach ((array)$defaults as $key => $value) { $result->{$key} = $value; } } return $results; } public function asArray() { return $this->_data; } public static function collectionToIds($collection) { $ids = []; foreach ($collection as $item) { $id = null; if (is_array($item)) { $id = $item['id']; } else { $id = $item->id; } if ($id != null) { $ids[] = $id; } } return $ids; } public function getSaveSql($table) { $sqlSnippets = []; foreach ($this->_data as $key => $value) { if ($key == 'id') { continue; } if (is_array($value)) { continue; } if (is_object($value)) { continue; } if (is_bool($value)) { $value = $value ? 1 : 0; } if ($value === null) { $sqlSnippet = "{$key} = null"; } else { $sqlSnippet = "{$key} = '" . addslashes($value) . "'"; } $sqlSnippets[] = $sqlSnippet; } return ($this->_data['id'] > 0 ? 'update' : 'insert into') . " {$table} set " . implode(',', $sqlSnippets) . ($this->_data['id'] > 0 ? " where id = {$this->_data['id']}" : ''); } /** * @param string $propName * @param null|string $lang * * @return string */ public function _($propName, $lang = null) { if ($lang === null) { $lang = LangUtils::getLang(); } $localizedPropName = "{$propName}_{$lang}"; if ($lang === null || $lang === 'cs') { $localizedPropName = $propName; } return $this->{$localizedPropName}; } public function __toString() { $out = get_class($this) . ': '; $itemsTxt = []; foreach (array_merge($this->_data, get_object_vars_compatible($this)) as $key => $value) { $value = json_encode($value); $itemsTxt[] = "{$key} = {$value}"; } $out .= implode(',', $itemsTxt); return $out; } /** * Specify data which should be serialized to JSON * @link http://php.net/manual/en/jsonserializable.jsonserialize.php * @return mixed data which can be serialized by <b>json_encode</b>, * which is a value of any type other than a resource. * @since 5.4.0 */ public function jsonSerialize() { // we do not want to include classes like Maternia_Translate or ServiceManager $attr = get_object_vars_compatible($this); foreach ($attr as $k => $a) { if (is_object($a) && ! ($a instanceof stdClass)) { unset($attr[$k]); } } return add($this->_data, $attr); } public function __debugInfo() { $class = new \ReflectionClass($this); $properties = []; /** @var \ReflectionProperty $staticProperty */ foreach ($class->getStaticProperties() as $staticProperty) { var_dump($staticProperty); $staticProperty->setAccessible(true); $properties[$staticProperty->getName()] = $staticProperty->getValue(); } /** @var \ReflectionProperty $staticProperty */ foreach ($class->getProperties() as $property) { $property->setAccessible(true); $properties[$property->getName()] = $property->getValue($this); } var_dump($properties, $class->getParentClass()); $data = $properties['_data']; unset($properties['_data']); return array_merge($properties, $data); } } $a = new RootObj(); $a->sfdgsdfg = 'sfgsdfg'; class Bb extends RootObj { private $test = 'sdfs'; private static $sss = 'sdfs'; } $b = new Bb(); $b->sfsdfgsdfg = 'asf'; var_dump($a, $b);

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.0160.00318.52
8.3.50.0120.00316.63
8.3.40.0090.00618.96
8.3.30.0120.00918.85
8.3.20.0040.00420.16
8.3.10.0000.00821.96
8.3.00.0040.00420.84
8.2.180.0120.00318.41
8.2.170.0090.00622.96
8.2.160.0040.01119.58
8.2.150.0050.00324.18
8.2.140.0080.00024.66
8.2.130.0080.00019.43
8.2.120.0040.00426.35
8.2.110.0070.00419.26
8.2.100.0000.01218.09
8.2.90.0030.00622.39
8.2.80.0060.00319.48
8.2.70.0000.00817.93
8.2.60.0040.00418.03
8.2.50.0060.00318.16
8.2.40.0040.00420.47
8.2.30.0000.00819.45
8.2.20.0030.00518.25
8.2.10.0000.00818.20
8.2.00.0000.00818.18
8.1.280.0100.01025.92
8.1.270.0050.00322.27
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0060.00319.40
8.1.230.0060.00621.10
8.1.220.0050.00317.91
8.1.210.0040.00420.75
8.1.200.0000.00817.48
8.1.190.0050.00317.48
8.1.180.0060.00318.10
8.1.170.0050.00318.74
8.1.160.0000.00718.84
8.1.150.0040.00420.58
8.1.140.0040.00419.65
8.1.130.0000.00720.61
8.1.120.0070.00317.51
8.1.110.0050.00317.45
8.1.100.0030.00717.52
8.1.90.0000.00817.57
8.1.80.0040.00417.61
8.1.70.0000.00917.42
8.1.60.0060.00317.51
8.1.50.0060.00317.52
8.1.40.0060.00317.57
8.1.30.0080.00017.74
8.1.20.0030.00617.64
8.1.10.0030.00517.63
8.1.00.0000.00817.64
8.0.300.0050.00319.80
8.0.290.0050.00317.00
8.0.280.0070.00018.43
8.0.270.0070.00017.32
8.0.260.0000.00818.97
8.0.250.0030.00317.02
8.0.240.0000.00817.11
8.0.230.0000.00817.13
8.0.220.0050.00317.03
8.0.210.0030.00417.02
8.0.200.0050.00317.02
8.0.190.0090.00017.03
8.0.180.0040.00417.06
8.0.170.0050.00217.06
8.0.160.0030.00517.14
8.0.150.0040.00417.04
8.0.140.0070.00017.00
8.0.130.0030.00313.45
8.0.120.0050.00316.88
8.0.110.0030.00516.93
8.0.100.0030.00517.10
8.0.90.0030.00517.04
8.0.80.0130.00717.02
8.0.70.0040.00417.10
8.0.60.0050.00217.00
8.0.50.0000.00717.02
8.0.30.0120.00717.34
8.0.20.0090.01217.42
8.0.10.0060.00316.97
8.0.00.0110.00716.78
7.4.330.0030.00315.55
7.4.320.0000.00616.63
7.4.300.0030.00316.69
7.4.290.0070.00316.67
7.4.280.0040.00416.59
7.4.270.0050.00316.61
7.4.260.0040.00416.55
7.4.250.0030.00516.55
7.4.240.0000.00716.72
7.4.230.0070.00016.59
7.4.220.0290.01216.79
7.4.210.0060.00816.66
7.4.200.0000.00716.52
7.4.160.0040.01116.52
7.4.150.0030.01417.40
7.4.140.0110.00917.86
7.4.130.0140.01116.70
7.4.120.0130.00716.59
7.3.330.0020.00513.32
7.3.320.0030.00313.57
7.3.310.0000.00716.53
7.3.300.0000.00716.49
7.3.290.0070.00016.33
7.3.280.0070.01016.48
7.3.270.0120.00617.40
7.3.260.0160.00516.72
7.3.250.0080.01416.46
7.3.240.0120.00816.58
7.1.80.2420.02316.57

preferences:
54.78 ms | 401 KiB | 5 Q