3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Arrayable { public function toArray(); } class Item implements Arrayable { protected $attributes = array(); protected $someParameter = true; public function __construct($attributes) { $this->attributes = $attributes; } public function toArray() { return $this->attributes; } } class ItemCollection implements Arrayable { protected $items = array(); public function addItem(Item $item) { $this->items[] = $item; } public function toArray() { $result = array(); foreach ($this->items as $item) { $result[] = $item->toArray(); } return $result; } } $array = array('foo', 'bar', 'baz'); $item = new Item($array); var_dump((array) $item); var_dump($item->toArray()); $collection = new ItemCollection(); $collection->addItem($item); $collection->addItem($item); var_dump((array) $collection); var_dump($collection->toArray());
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { ["*attributes"]=> array(3) { [0]=> string(3) "foo" [1]=> string(3) "bar" [2]=> string(3) "baz" } ["*someParameter"]=> bool(true) } array(3) { [0]=> string(3) "foo" [1]=> string(3) "bar" [2]=> string(3) "baz" } array(1) { ["*items"]=> array(2) { [0]=> object(Item)#1 (2) { ["attributes":protected]=> array(3) { [0]=> string(3) "foo" [1]=> string(3) "bar" [2]=> string(3) "baz" } ["someParameter":protected]=> bool(true) } [1]=> object(Item)#1 (2) { ["attributes":protected]=> array(3) { [0]=> string(3) "foo" [1]=> string(3) "bar" [2]=> string(3) "baz" } ["someParameter":protected]=> bool(true) } } } array(2) { [0]=> array(3) { [0]=> string(3) "foo" [1]=> string(3) "bar" [2]=> string(3) "baz" } [1]=> array(3) { [0]=> string(3) "foo" [1]=> string(3) "bar" [2]=> string(3) "baz" } }

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:
44.21 ms | 403 KiB | 8 Q