Static Variable Outside A Method

no-email (Damien Seguy), Damien Seguy
Tue, 07 Nov 2023 00:00:00 +0000

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.