<?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());
- 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.5.24 - 5.5.30, 5.6.8 - 5.6.16
- Parse error: syntax error, unexpected ';' in /in/lOpsm on line 76
Process exited with code 255.
preferences:
173.69 ms | 1395 KiB | 24 Q