Sometimes we need to populate static variables in php (e.g. populating associative arrays from existing arrays). Easiest way is to define a static function (e.g. init()) and then call it statically after the class.
<?php
class Foo {
static $a = ["foo", "bar"];
static $aa = array();
static function init () {
foreach (self::$a as $val) {
self::$aa[$val] = 1;
}
}
}
Foo::init();
print_r(Foo::$aa);
?>Array
(
[foo] => 1
[bar] => 1
)
Env: PHP 8.2.29 (Linux)