PHP Classes

Question

Recommend this page to a friend!

      Chavão Template Manager  >  All threads  >  Question  >  (Un) Subscribe thread alerts  
Subject:Question
Summary:Should Variable be initialized ???
Messages:3
Author:John Guerin
Date:2010-01-26 15:22:18
Update:2010-01-27 09:18:17
 

  1. Question   Reply   Report abuse  
Picture of John Guerin John Guerin - 2010-01-26 15:22:18
Referring to the line of code that is replacing an array of vars ...

$sReturn .= str_replace("{".$sTarget."}",$sValue,$sHtml);
$arrHtml[$iLine] = $sReturn;

I note that $sReturn is not set initially ... $sReturn="";

Should it be ???

Thanks for this class.

John Guerin

  2. Re: Question   Reply   Report abuse  
Picture of DC DC - 2010-01-27 03:56:35 - In reply to message 1 from John Guerin
No need to initialize the variable $sReturn, because it is in the scope of the function, so "initiliazed" without value by default. And in each iteration the variable is deallocated using "unset", but could also be getting an empty string $sReturn ="". No matter the place, can be in the end or in the beginning of the first foreach.

  3. Re: Question   Reply   Report abuse  
Picture of John Guerin John Guerin - 2010-01-27 09:18:17 - In reply to message 2 from DC
Thanks Diego ... I wasn't thinking clearly ... the unset does all that is needed to be done

Thanks

John