Can static variables be initialized by a call to a function?
For example, is this possible:
static $domain = "http://" . getDomain();
I always get time out execution on stuffs like this.
Well, let's see what the manual has to say about [man]static[/man]:
Note: Static variables may be declared as seen in the examples above. Trying to assign values to these variables which are the result of expressions will cause a parse error. Example 12.8. Declaring static variables<?php function foo(){ static $int = 0; // correct static $int = 1+2; // wrong (as it is an expression) static $int = sqrt(121); // wrong (as it is an expression too) $int++; echo $int; } ?>
Note: Static variables may be declared as seen in the examples above. Trying to assign values to these variables which are the result of expressions will cause a parse error. Example 12.8. Declaring static variables
<?php function foo(){ static $int = 0; // correct static $int = 1+2; // wrong (as it is an expression) static $int = sqrt(121); // wrong (as it is an expression too) $int++; echo $int; } ?>
Therefore, no, you cannot do that.
Thanks. Resolved