I am wondering why is it that my static variable initialization does not work with the following declaration:
function validate()
{
static $timezones = DateTimeZone::listIdentifiers(); // Error here
...
}
The line with static ...
generates the error:
PHP Fatal error: Constant expression contains invalid operations
If I do the following, though, it works as expected:
function validate()
{
static $timezones = null;
if(!isset($timezones))
{
$timezones = DateTimeZone::listIdentifiers();
}
...
}
So I have a way around the problem, but I am wondering why is it that the first method fails?