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?
Suppose a class, foo , has one static variable, bar . Is it possible
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.