Welcome Guest, Not a member yet? Register   Sign In
A question about load_class function in Common.php
#1

[eluser]Crusoe[/eluser]
In this block of code

Code:
static $_classes = array();
   // Does the class exist?  If so, we're done...
   if (isset($_classes[$class]))
     {
      return $_classes[$class];
     }

The $isset test not make any sense. Can someone explain this please ?
#2

[eluser]danmontgomery[/eluser]
It's checking if the class has already been loaded, in which case it doesn't load it again.
#3

[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.
#4

[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.
#5

[eluser]Crusoe[/eluser]
Ah. I see what you mean.

Code:
static $arry = array();
  $arry['a'] = 'hello world';
  static $arry = array();
  if(isset($arry['a'])) {
     print $arry['a'];
  }

prints "hello world"

I am new to PHP (uses C++ and C# mostly). Just getting used to PHP's peculiarities Smile

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB