A question about load_class function in Common.php - 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: A question about load_class function in Common.php (/showthread.php?tid=42646) |
A question about load_class function in Common.php - El Forum - 06-14-2011 [eluser]Crusoe[/eluser] In this block of code Code: static $_classes = array(); The $isset test not make any sense. Can someone explain this please ? A question about load_class function in Common.php - El Forum - 06-14-2011 [eluser]danmontgomery[/eluser] It's checking if the class has already been loaded, in which case it doesn't load it again. A question about load_class function in Common.php - El Forum - 06-14-2011 [eluser]Crusoe[/eluser] The if (isset($_classes[$class])) will always return false because the array is being initialised in the previous line. It's meaningless to have that isset test there. A question about load_class function in Common.php - El Forum - 06-14-2011 [eluser]danmontgomery[/eluser] [quote author="Crusoe" date="1308065319"]The if (isset($_classes[$class])) will always return false because the array is being initialised in the previous line. It's meaningless to have that isset test there.[/quote] http://php.net/manual/en/language.variables.scope.php Quote:A static variable exists only in a local function scope, but it does not lose its value when program execution leaves this scope. A question about load_class function in Common.php - El Forum - 06-14-2011 [eluser]Crusoe[/eluser] Ah. I see what you mean. Code: static $arry = array(); prints "hello world" I am new to PHP (uses C++ and C# mostly). Just getting used to PHP's peculiarities Thanks. |