3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function x($o) { return get_object_vars($o);} class A { public $a; public $b; private $c; protected static $columnRegistry = array(); protected $columns = array(); public function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; $this->setupColumns(); } public function toArray() { $ret = []; foreach ($this->columns as $column) { $ret[$column] = $this->$column; } return $ret; } protected function setupColumns() { $class = get_class($this); // Define columns for current row if (!array_key_exists($class, self::$columnRegistry)) { $this->columns = array_keys(x($this)); self::$columnRegistry[$class] = $this->columns; } else { $this->columns = self::$columnRegistry[$class]; } } } $expected = [ 'a' => 1, 'b' => 2, ]; $numReps = 100000; $start = microtime(true); for($i = 0; $i < $numReps; $i++) { $o = new A(1, 2, 3); $res = $o->toArray(); if ($res !== $expected) { throw new Exception("Not same"); } } $end = microtime(true); $mem = memory_get_peak_usage(true); echo number_format($end-$start, 8) . "\t$mem\n";
Output for 7.1.0
0.08633900 2097152
Output for 7.0.14
0.04956102 2097152
Output for 7.0.6
0.05324697 2097152
Output for 7.0.5
0.06290102 2097152
Output for 7.0.4
0.05443001 2097152
Output for 7.0.3
0.05045199 2097152
Output for 7.0.2
0.06214309 2097152
Output for 7.0.1
0.04850602 2097152
Output for 7.0.0
0.06511521 2097152
Output for hhvm-3.12.0
0.23792410 313816
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.6.28
0.19574690 262144
Output for 5.6.21
0.14302111 262144
Output for 5.6.20
0.11778617 262144
Output for 5.6.19
0.11927009 262144
Output for 5.6.18
0.11706400 262144
Output for 5.6.17
0.11920619 262144
Output for 5.6.16
0.12358594 262144
Output for 5.6.15
0.13267994 262144
Output for 5.6.14
0.12478590 262144
Output for 5.6.13
0.12078881 262144
Output for 5.6.12
0.11776209 262144
Output for 5.6.11
0.12791610 262144
Output for 5.6.10
0.12505007 262144
Output for 5.6.9
0.13328600 262144
Output for 5.6.8
0.13226104 262144
Output for 5.6.7
0.12111306 262144
Output for 5.5.35
0.13950992 262144
Output for 5.5.34
0.15112400 262144
Output for 5.5.33
0.14086294 262144
Output for 5.5.32
0.13550401 262144
Output for 5.5.31
0.14836287 262144
Output for 5.5.30
0.15921402 262144
Output for 5.5.29
0.13310099 262144
Output for 5.5.28
0.14723682 262144
Output for 5.5.27
0.14124084 262144
Output for 5.5.26
0.16288400 262144
Output for 5.5.25
0.14415598 262144
Output for 5.5.24
0.14759898 262144
Output for 5.4.45
0.23782015 262144
Output for 5.4.44
0.30093908 262144
Output for 5.4.43
0.48032308 262144
Output for 5.4.42
0.30787992 262144
Output for 5.4.41
0.26512408 262144
Output for 5.4.40
0.27728510 262144
Output for 5.4.39
0.25041413 262144
Output for 5.4.38
0.24307799 262144
Output for 5.4.37
0.21426010 262144
Output for 5.4.36
0.22784686 262144
Output for 5.4.35
0.41073012 262144
Output for 5.4.34
0.23582292 262144
Output for 5.4.32
0.20774412 262144
Output for 5.4.31
0.20466185 262144
Output for 5.4.30
0.20882511 262144
Output for 5.4.29
0.18912721 262144
Output for 5.4.28
0.20802307 262144
Output for 5.4.27
0.21246791 262144
Output for 5.4.26
0.22435188 262144
Output for 5.4.25
0.20362997 262144
Output for 5.4.24
0.20691609 262144
Output for 5.4.23
0.20157695 262144
Output for 5.4.22
0.23986816 262144
Output for 5.4.21
0.34207416 262144
Output for 5.4.20
0.20392609 262144
Output for 5.4.19
0.21899486 262144
Output for 5.4.18
0.24569607 262144
Output for 5.4.17
0.20317101 262144
Output for 5.4.16
0.21491694 262144
Output for 5.4.15
0.19143987 262144
Output for 5.4.14
0.24007106 262144
Output for 5.4.13
0.20523500 262144
Output for 5.4.12
0.21559620 262144
Output for 5.4.11
0.23767591 262144
Output for 5.4.10
0.22723913 262144
Output for 5.4.9
0.29547119 262144
Output for 5.4.8
0.23845196 262144
Output for 5.4.7
0.22744107 262144
Output for 5.4.6
0.21677399 262144
Output for 5.4.5
0.24532890 262144
Output for 5.4.4
0.21120095 262144
Output for 5.4.3
0.27328992 262144
Output for 5.4.2
0.25635910 262144
Output for 5.4.1
0.26363087 262144
Output for 5.4.0
0.23191190 262144
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/rhljP on line 21
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/rhljP on line 21
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/rhljP on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/rhljP on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/rhljP on line 5
Process exited with code 255.