Is it possible to create static variables at runtime in PHP?
Suppose a class, foo
, has one static variable, bar
. Is it possible to write PHP code that will create a new static variable, bar2
, for the foo
class at runtime?
No, it's not possible.
A static variable is, as its name says, allocated statically at compile time. It cannot be allocated during runtime, nor can it be deallocated (e.g.: unset) during runtime either.
Also, static variables are independent of the call stack.
You can read more on Wikipedia.
精彩评论