0

maybe it's a noob question, but I'm unable to understand why my variable "$numero_requete_en_cours_exe" is returning 0 instead of 3... This is a global variable yet !

 $numero_requete_en_cours_exe = 0;

 affichagetypemessage(0);

 function affichagetypemessage($id_message_page){

     do{
    // operation with $id_message_page...
    $numero_requete_en_cours_exe++;
    } while ($numero_requete_en_cours_exe !=3);

 }

echo $numero_requete_en_cours_exe;
Dimitri
  • 33
  • 8
  • The variable is local to the function. – Barmar Sep 22 '17 at 23:52
  • I eddited, I forgot the global variable at the top. Sorry – Dimitri Sep 23 '17 at 00:05
  • It's still local to the function. If you want to access the global variable inside the function, you need to put `global $numero_requete_en_cours_exe;` inside the function. – Barmar Sep 23 '17 at 00:11
  • But that's bad programming style, you should pass the variable as an argument and return the updated value as a value. – Barmar Sep 23 '17 at 00:12
  • Well, I read that in this post -> Reference: What is variable scope, which variables are accessible from where and what are “undefined variable” errors? Thank a lot ! It's works with global, and it's work with passing the variable as an argument too ;) – Dimitri Sep 23 '17 at 00:19

0 Answers0