3v4l.org

run code in 300+ PHP versions simultaneously
<?php define("UV_VERSION", "1.2.0"); define("UV_LIB_VERSION", "1.0.1"); class UVArray extends UVObject { public function add($object) { $count = count(get_object_vars($this)); $this->$count = new UVObject($object); } public function set($key, $value) { if (is_numeric($key)) { $this->$key = $value; } } } class UVObject { public function __construct($attributes=array()) { if (!empty($attributes)) { foreach ($attributes as $key => $value) { $this->set($key, $value); } } $this->convertNestedObjects(); } public function set($key, $value) { $this->$key = $value; } public function get($index) { return $this->$index; } public function toArray() { $obj = array(); $vars = get_object_vars($this); foreach ($vars as $key => $value) { if (is_object($value) && method_exists($value, "toArray")) { $obj[$key] = $value->toArray(); } else { $obj[$key] = $value; } } if (count($obj) == 0 && !($this instanceof UVArray)) { return new stdClass(); } return $obj; } public function isEmpty() { $vars = get_object_vars($this); if (empty($vars)) { return true; } else if (count($vars) === 1 && isset($vars["line_items"]) && count(get_object_vars($vars["line_items"])) == 0) { return true; } else if (count($vars) === 1 && isset($vars["items"]) && count(get_object_vars($vars["items"])) == 0) { return true; } else if (count($vars) === 2 && isset($vars["linked_products"]) && count(get_object_vars($vars["linked_products"])) == 0 && isset($vars["reviews"]) && count(get_object_vars($vars["reviews"])) == 0) { return true; } else { return false; } } private function convertNestedObjects() { $vars = get_object_vars($this); foreach($vars as $key => $value) { if (is_array($value) && $this->isAssociative($value)) { $this->$key = new UVObject($value); } else if (is_array($value)) { $this->$key = new UVArray($value); } } } private function isAssociative($arr) { return array_keys($arr) !== range(0, count($arr) - 1); } } class BuildUV extends UVObject { public function __construct() { $this->set("page", new UVObject()); $this->set("user", new UVObject()); $this->set("product", new UVObject()); $this->get("product")->set("linked_products", new UVArray()); $this->get("product")->set("reviews", new UVArray()); $this->set("listing", new UVObject()); $this->get("listing")->set("items", new UVArray()); $this->set("transaction", new UVObject()); $this->get("transaction")->set("line_items", new UVArray()); $this->set("basket", new UVObject()); $this->get("basket")->set("line_items", new UVArray()); $this->set("events", new UVArray()); $this->set("recommendation", new UVArray()); } public function toJSON() { $uvOutput = array(); $uvOutput["page"] = $this->page->toArray(); $uvOutput["user"] = $this->user->toArray(); $uvOutput["events"] = $this->events->toArray(); $uvOutput["version"] = UV_VERSION; $uvOutput["php_lib_version"] = UV_LIB_VERSION; $vars = get_object_vars($this); foreach ($vars as $key => $value) { if (isset($uvOutput[$key])) { continue; } if (method_exists($value, "isEmpty") && !$value->isEmpty()) { if (method_exists($value, "toArray")) { $uvOutput[$key] = $value->toArray(); } else { $uvOutput[$key] = $value; } } } return json_encode($uvOutput); } public function toHTML() { return "\n <!-- Qubit Universal Variable data layer v" + UV_VERSION + " - PHP Lib v" + UV_LIB_VERSION + " --> <script> window.universal_variable = " . $this->toJSON() . "; </script> <!-- End UV --> \n"; } } ?> <?php $uv = new BuildUV(); $uv->get("page")->set("category", "Home"); $uv->get("page")->set("subcategory", "Mens - Shoes"); print $uv->toJSON(); => {"page":{"category":"Home","subcategory":"Mens - Shoes"},"user":{},"events":[]} ?>

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)
5.4.260.0130.06212.43
5.4.250.0060.04412.43
5.4.240.0090.04512.43
5.4.230.0080.04212.42
5.4.220.0080.04312.42
5.4.210.0070.04012.42
5.4.200.0070.04312.42
5.4.190.0080.03812.42
5.4.180.0070.03512.42
5.4.170.0080.04012.43
5.4.160.0060.03812.42
5.4.150.0050.03912.42
5.4.140.0080.03812.11
5.4.130.0080.03712.09
5.4.120.0080.03412.05
5.4.110.0060.03612.05
5.4.100.0070.03712.05
5.4.90.0070.03712.05
5.4.80.0070.03812.05
5.4.70.0070.03812.04
5.4.60.0070.03912.05
5.4.50.0060.03912.05
5.4.40.0050.04112.04
5.4.30.0040.03912.03
5.4.20.0060.03712.03
5.4.10.0080.03612.03
5.4.00.0050.03811.52
5.3.280.0050.03912.72
5.3.270.0070.04112.74
5.3.260.0080.04112.74
5.3.250.0060.04312.74
5.3.240.0080.04012.74
5.3.230.0090.04112.73
5.3.220.0080.04612.69
5.3.210.0090.04712.69
5.3.200.0090.05012.69
5.3.190.0070.05012.70
5.3.180.0080.04612.69
5.3.170.0090.04912.69
5.3.160.0110.05212.69
5.3.150.0100.04812.69
5.3.140.0110.04812.68
5.3.130.0110.05512.68
5.3.120.0070.04612.68
5.3.110.0070.04312.68
5.3.100.0060.04012.16
5.3.90.0060.03812.14
5.3.80.0050.03812.13
5.3.70.0070.04212.13
5.3.60.0070.05112.11
5.3.50.0070.04312.06
5.3.40.0090.04112.06
5.3.30.0070.04712.03
5.3.20.0060.04411.81
5.3.10.0070.04811.77
5.3.00.0060.03911.76
5.2.170.0060.0309.27
5.2.160.0050.0359.27
5.2.150.0040.0389.26
5.2.140.0030.0399.26
5.2.130.0040.0319.22
5.2.120.0030.0309.22
5.2.110.0070.0389.23
5.2.100.0050.0319.23
5.2.90.0050.0309.22
5.2.80.0050.0359.22
5.2.70.0060.0319.21
5.2.60.0070.0349.17
5.2.50.0060.0379.15
5.2.40.0050.0339.12
5.2.30.0060.0329.09
5.2.20.0070.0379.09
5.2.10.0050.0328.99
5.2.00.0060.0338.85
5.1.60.0040.0278.15
5.1.50.0060.0268.15
5.1.40.0030.0278.13
5.1.30.0040.0298.48
5.1.20.0050.0328.50
5.1.10.0050.0308.22
5.1.00.0040.0288.22
5.0.50.0040.0216.71
5.0.40.0030.0226.57
5.0.30.0040.0316.39
5.0.20.0040.0226.36
5.0.10.0030.0216.33
5.0.00.0040.0346.32
4.4.90.0030.0164.78
4.4.80.0040.0154.75
4.4.70.0030.0164.76
4.4.60.0030.0164.76
4.4.50.0050.0164.77
4.4.40.0040.0274.71
4.4.30.0040.0164.76
4.4.20.0040.0164.84
4.4.10.0030.0184.85
4.4.00.0040.0254.76
4.3.110.0050.0194.67
4.3.100.0020.0174.67
4.3.90.0020.0184.63
4.3.80.0050.0254.58
4.3.70.0030.0154.63
4.3.60.0020.0174.63
4.3.50.0020.0174.63
4.3.40.0020.0304.53
4.3.30.0020.0183.37
4.3.20.0020.0183.36
4.3.10.0010.0183.33
4.3.00.0000.0237.27

preferences:
142.78 ms | 1394 KiB | 7 Q