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' => 'qux'); $item = new Item($array); print_r((array) $item); print_r($item->toArray()); $collection = new ItemCollection(); $collection->addItem($item); $collection->addItem($item); print_r((array) $collection); print_r($collection->toArray());
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [*attributes] => Array ( [foo] => bar [baz] => qux ) [*someParameter] => 1 ) Array ( [foo] => bar [baz] => qux ) Array ( [*items] => Array ( [0] => Item Object ( [attributes:protected] => Array ( [foo] => bar [baz] => qux ) [someParameter:protected] => 1 ) [1] => Item Object ( [attributes:protected] => Array ( [foo] => bar [baz] => qux ) [someParameter:protected] => 1 ) ) ) Array ( [0] => Array ( [foo] => bar [baz] => qux ) [1] => Array ( [foo] => bar [baz] => qux ) )

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