Salut,
Je comprends pas l'interet d'Iterator aggregate quelqu'un peut m'éclairer?
Dans la docs y'a un exemple :
Mais si j'enleve l'implementation :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 class myData implements IteratorAggregate { public $property1 = "Propriété publique numéro un"; public $property2 = "Propriété publique numéro deux"; public $property3 = "Propriété publique numéro trois"; public function __construct() { $this->property4 = "dernière propriété"; } public function getIterator() { return new ArrayIterator($this); } } $obj = new myData; foreach($obj as $key => $value) { var_dump($key, $value); echo "\n"; }
ca ne change absolument rien a mon résultat en sortie :/
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 class myData2 { public $property1 = "Propriété publique numéro un"; public $property2 = "Propriété publique numéro deux"; public $property3 = "Propriété publique numéro trois"; public function __construct() { $this->property4 = "dernière propriété"; } } $obj2 = new myData2; foreach($obj2 as $key => $value) { var_dump($key, $value); echo "\n"; }
Je comprend pas tout je crois![]()







Répondre avec citation






Partager