3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class PieceOfSheet { private $cells = []; function add($name, $value) { $this->cells[$name] = $value; } function get($name) { return $this->cells[$name]; } function all() { return $this->cells; } } class Person { public $name; public $age; public $gender; public $from; function __construct($name, $age, $gender, $from) { $this->name = $name; $this->age = $age; $this->gender = $gender; $this->from = $from; } } class StuffDoer { private $sheet; function __construct(PieceOfSheet $sheet) { $this->sheet = $sheet; } function doStuff() { $data = [ 'prathna' => function (Person $person) { return $person->name; }, 'chris' => function (Person $person) { return $person->gender; }, 'adam' => function (Person $person) { return $person->from; }, 'deepthi' => function (Person $person) { return $this->age; } ]; foreach (['adam', 'chris', 'prathna'] as $name) { $this->addMoreSheet($this->sheet, $data[$name]); } return $this->sheet->all(); } function addMoreSheet(PieceOfSheet $sheet, $cell, callable $getData, Person $person) { $sheet->add($cell, call_user_func_array($getData, [$person]); } } $s = new StuffDoer(new PieceOfSheet()); var_dump($s->doStuff());
based on E67Z4
Output for 7.0.0
Parse error: syntax error, unexpected ';', expecting ',' or ')' in /in/lOpsm on line 76
Process exited with code 255.
Output for 5.4.10 - 5.6.16
Parse error: syntax error, unexpected ';' in /in/lOpsm on line 76
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/lOpsm on line 5
Process exited with code 255.