Fonction - méthode - foreach
Bonjour
Pige pas, j'ai 2 classes Form & String et un tableau de Form qui contient les instances de String ajoutés par la méthode addString (voir C ==> )de Form
Les codes importants sont en gras
Code:
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 51 52 53 54 55 56 57 58 59 60 61
|
class Form /*extends Stack/*/ {
A ==> private $formTitle, $eventList = NULL, $debug ;
private $cnt = 0, $form = array(), $stackMsg = array(), $cntMsg = 0, $event ;
private $msg = VIDE, $tabMsg = array( VIDE => "Prêt â recevoir l'encodade de votre formulaire" ,
KO => "Veuillez corriger les fautes/complètez votre formulaire" ,
OK => "Parfait, pas(plus) d'erreur(s) dans ce formulaire"
) ;
function __construct($formTitle,$eventList,$debug=true)
{ $this->formTitle = $formTitle ;
$this->eventList = $eventList ;
$this->debug = $debug ;
$this->event = new Event($this->eventList) ;
// $this->stack = new Stack() ;
$this->form = NULL ;
$this->stackMsg = NULL ;
$this->cntMsg = 0 ;
if ($this->getDebug())
print("Form[__construct]" . CRLF) ;
}
............
/**
* FORM: validateForm
*
*/
function validateForm() {
$i = 0 ;
$formValidate = true ;
$formCntfilled = 0 ;
$formMust = 0;
$retVal = OK ;
if ($this->getDebug())
print("Form[validateForm]" . CRLF) ;
foreach($this->form as $key => $value) {
foreach($value as $fld => $val) {
print_r("==> " . $fld . " - " . $val . CRLF) ;
}
print("Form ValidateField N°[".$key."]" . CRLF) ;
$retVal = $value->validateField() ;
echo "Key: $key return[".$retVal."]" . CRLF ;
}
return($this->isFormValid()) ;
}
/**
* FORM: addString
*
*/
C ==> function addString($fldName, $fldMust, $fldType, $fldError, $FldMinl, $fldMaxl) {
if ($this->getDebug())
print("Form[addString][$fldName]" . CRLF) ;
$this->form[$this->cnt++] = new String($fldName, $fldMust, $fldType, $fldError, $FldMinl, $fldMaxl) ;
} |
Selon moi, this->form est un tableau alimenté par la méthode addString et contient donc des instances de la class String ajoutés par la méthode addString
Dans la méthode evaluateForm j'ai le code:
Code:
1 2 3 4
| foreach($this->form as $key => $value) {
foreach($value as $fld => $val) {
print_r("==> " . $fld . " - " . $val . CRLF) ;
} |
qui imprime:
Code:
1 2 3 4 5 6 7 8 9 10 11
|
==> formTitle -
==> eventList -
==> debug -
==> cnt - 0
==> form - Array
==> stackMsg - Array
==> cntMsg - 0
==> event -
==> msg - -1
==> tabMsg - Array |
Mon souci principal est que ces impressions sont les propriétés de la class Form et non celles de la classe String
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
class String extends Form // extends Stack /* implements MethodList */
{
private $fldName, $fieldValue = NULL, $fldMust, $fldType, $fldError, $fldMinl, $fldMaxl, $debug ;
const _Alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
const _Num = "0123456789" ;
const _Dec = "0123456789.," ;
const _Email = "-_." ;
const _E = "" ;
const _Ponct = ".,?!\=" ;
B ==> function __construct($fldName, $fldMust, $fldType, $fldError, $fldMinl, $fldMaxl, $debug=TRUE) {
$this->fldName = $fldName ;
$this->fldMust = $fldMust ;
$this->fldType = $fldType ;
$this->fldError = $fldError ;
$this->fldMinl = $fldMinl ;
$this->fldMaxl = $fldMaxl ;
$this->debug = $debug ; |
Voir A ==> & B==> dans les fragments de code ci-dessus....
Ceci afin de clarifier mon souci...
Merci de votre éclairage