Bonjour, Après quelques mois d'absence, je le remets à PHP...
Pas évident!
Bref, j'ai réduit mon application à un petit exemple pour test...
Mon questionnement est tout à fait d'actualité quand j'ai été surpris d'avoir les mêmes résultats même en commentant l'extends
Je vous soumets mon petit exemple pour avoir vos commentaires
Le voici
Lequel affiche:
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
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
48
49
50 <?php define("CRLF" , "<br>\n") ; // ------------------------------------------------------------------------------------------------------------------------------------------------- // /** * FORM constructor * */ class Form { private $cnt = 0 , $form ; function __construct($form) { $this->form = $form ; $this->cnt = count($form) ; print("Form|__construct]" . CRLF) ; } function initForm() { print("Form|initForm]" . CRLF) ; for($i = 0 ; $i < $this->cnt ; $i++) { TEXT::initForm() ; } } } class Text //extends Form { private $fld ; function __construct($fld) { $this->fld = $fld ; print("Text|__construct][$fld]" . CRLF) ; } function initForm() { print("Text|initForm]" . CRLF) ; } function filled() { print("Text|filled]" . CRLF) ; } } $cf = new Form (array ( new Text ( "prénom" ) , new Text ( "nom" ) ) ) ; $cf->initForm() ; ?>
La méthode Text est supposée être multiple et le tableau $cf contenir différents objet.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 Text|__construct][prénom] Text|__construct][nom] Form|__construct] Form|initForm] Text|initForm] Text|initForm]
Merci à vous tous
Partager