3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php 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)) { foreach ((new ReflectionClass($this))->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { if (!$property->isStatic()) { $this->columns[] = $property->getName(); } } 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.09035301 2097152
Output for 7.0.14
0.08438396 2097152
Output for 7.0.6
0.05930996 2097152
Output for 7.0.5
0.06172013 2097152
Output for 7.0.4
0.08849287 2097152
Output for 7.0.3
0.05070400 2097152
Output for 7.0.2
0.06793594 2097152
Output for 7.0.1
0.05290890 2097152
Output for 7.0.0
0.06130695 2097152
Output for hhvm-3.12.0
0.31705093 315888
Output for hhvm-3.10.0
0.14390993 314280
Output for 5.6.28
0.18958712 262144
Output for 5.6.21
0.13078189 262144
Output for 5.6.20
0.13772607 262144
Output for 5.6.19
0.12230301 262144
Output for 5.6.18
0.12323594 262144
Output for 5.6.17
0.12338495 262144
Output for 5.6.16
0.14014912 262144
Output for 5.6.15
0.12621593 262144
Output for 5.6.14
0.13889885 262144
Output for 5.6.13
0.11841893 262144
Output for 5.6.12
0.14161801 262144
Output for 5.6.11
0.14655209 262144
Output for 5.6.10
0.13157701 262144
Output for 5.6.9
0.12655807 262144
Output for 5.6.8
0.13326097 262144
Output for 5.6.7
0.12745905 262144
Output for 5.5.35
0.14861393 262144
Output for 5.5.34
0.14296198 262144
Output for 5.5.33
0.16086197 262144
Output for 5.5.32
0.13413787 262144
Output for 5.5.31
0.13787889 262144
Output for 5.5.30
0.14973307 262144
Output for 5.5.29
0.13475394 262144
Output for 5.5.28
0.14983702 262144
Output for 5.5.27
0.12843299 262144
Output for 5.5.26
0.14619184 262144
Output for 5.5.25
0.15365505 262144
Output for 5.5.24
0.12707496 262144
Output for 5.4.45
0.16185713 262144
Output for 5.4.44
0.13315392 262144
Output for 5.4.43
0.24664998 262144
Output for 5.4.42
0.28326011 262144
Output for 5.4.41
0.39186001 262144
Output for 5.4.40
0.31131697 262144
Output for 5.4.39
0.28565907 262144
Output for 5.4.38
0.26799393 262144
Output for 5.4.37
0.33305192 262144
Output for 5.4.36
0.30327010 262144
Output for 5.4.35
0.27475500 262144
Output for 5.4.34
0.18576193 262144
Output for 5.4.32
0.18076110 262144
Output for 5.4.31
0.20360780 262144
Output for 5.4.30
0.20240688 262144
Output for 5.4.29
0.19612598 262144
Output for 5.4.28
0.22204995 262144
Output for 5.4.27
0.19708920 262144
Output for 5.4.26
0.20090413 262144
Output for 5.4.25
0.20452881 262144
Output for 5.4.24
0.20513391 262144
Output for 5.4.23
0.20066786 262144
Output for 5.4.22
0.21206594 262144
Output for 5.4.21
0.20024300 262144
Output for 5.4.20
0.19742107 262144
Output for 5.4.19
0.21290779 262144
Output for 5.4.18
0.21081400 262144
Output for 5.4.17
0.20144701 262144
Output for 5.4.16
0.26666594 262144
Output for 5.4.15
0.20486403 262144
Output for 5.4.14
0.19896698 262144
Output for 5.4.13
0.20975614 262144
Output for 5.4.12
0.21010780 262144
Output for 5.4.11
0.24706888 262144
Output for 5.4.10
0.29598188 262144
Output for 5.4.9
0.22762299 262144
Output for 5.4.8
0.20659304 262144
Output for 5.4.7
0.32287002 262144
Output for 5.4.6
0.20000100 262144
Output for 5.4.5
0.20870113 262144
Output for 5.4.4
0.19522500 262144
Output for 5.4.3
0.21086502 262144
Output for 5.4.2
0.20975494 262144
Output for 5.4.1
0.21331406 262144
Output for 5.4.0
0.22093391 262144
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/IA37E on line 19
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/IA37E on line 19
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/IA37E on line 4
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/IA37E on line 4
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/IA37E on line 4
Process exited with code 255.