3v4l.org

run code in 300+ PHP versions simultaneously
<?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; for($i = 0; $i < $numReps; $i++) { $o = new A(1, 2, 3); $res = $o->toArray(); if ($res !== $expected) { throw new Exception("Not same"); } } echo "OK";
Output for git.master, git.master_jit, rfc.property-hooks
OK

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
74.51 ms | 401 KiB | 8 Q