Page 1 of 1

Life and scope of static member properties

Posted: Mon Mar 09, 2009 9:51 am
by cbc
Hi:

PHP5. If I create a class with a static member property (variable) and I use value of that property during the execution of a script what happens if other requests are made for the same script? If I were instantiating an object, each instance could be changed independently without affecting the others. But what if it's a static variable?

If I have multiple HTTP requests for the same script, and the variable is changed in each, will changes in one affect the other?

??

Please advise.

THANKS MUCH!

Re: Life and scope of static member properties

Posted: Mon Mar 09, 2009 10:08 am
by Mark Baker
Individual http request are running in their own thread, so changes made to a static property by one will not affect any of the other threads. Changing a static property within a thread will affect any subsequent access to that proprty within that individual thread

Re: Life and scope of static member properties

Posted: Mon Mar 09, 2009 10:30 am
by cbc
Mark:

Thank you. I suspected as much, and that was certainly the answer I wanted to hear, but it's good to get confirmation from someone with more experience!

Regards,

-cbc