-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisting3.php
47 lines (36 loc) · 975 Bytes
/
listing3.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
class Person {
public $firstname = '';
public $lastname = '';
function __toString(): string {
return $this->firstname.' '.$this->lastname;
}
}
class PersonList {
private $_myList = array();
function add(callable $config) {
$p = new Person;
$this->_myList[] = $p;
$config($p);
}
function each(callable $action) {
foreach($this->_myList as $p)
$action($p);
}
}
$popolation = new PersonList;
$popolation->add( function(Person $p) {
$p->firstname = 'Micky';
$p->lastname = 'Maus';
});
$popolation->add( function(Person $p) {
$p->firstname = 'Goofy';
});
$popolation->add( function(Person $p) {
$p->firstname = 'Donald';
$p->lastname = 'Duck';
});
$popolation->each( function(Person $p) {
echo $p.'<br>';
});
?>