Static Variable Outside A Method

TIL that PHP static variables can be declared out of a function, in the namespace.

Then, it is a simple variable with a default value. There is no way to call the global scope again (that makes no sense). In fact, including the same file simply restarts the context and the static variable again.

May be a warning from the linter could be nice.

In PHP 8.3, duplicate ‘static’ variable definitions is forbidden. Not in a loop, which is a bad practice anyway.

../_images/static_outside_method.png