Initializing arrays - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Initializing arrays (/showthread.php?tid=24224) |
Initializing arrays - El Forum - 11-03-2009 [eluser]trenchard[/eluser] In most tutorials I don't see people initializing arrays. In other places I hear that it is good practice and can help PHP deal with certain scenarios. Should I be initializing all my arrays? Initializing arrays - El Forum - 11-03-2009 [eluser]saidai jagan[/eluser] Yeah it is a good practice to initialize arrays Initializing arrays - El Forum - 11-03-2009 [eluser]trenchard[/eluser] Thanks. It makes sense to me to initialize all variable as well. Initializing arrays - El Forum - 11-03-2009 [eluser]BrianDHall[/eluser] [quote author="trenchard" date="1257286355"]Thanks. It makes sense to me to initialize all variable as well.[/quote] If nothing else you never again run into those darn PHP errors that refer to referencing an uninitialized variable. It helps for lots of reasons, and it is indeed just a good practice and habit to have. PHP is one of the only languages that even lets you get away with using variables without initializing. One thing I do not do, however, is go out of my way to initialize everything if I'm going to be using something for the first time and immediately assigning it to a variable. For instance: Code: $var = $foo + 2 / 1.5; In both cases I see no reason to just initialize to be initializing - so don't get too carried away |