Life and scope of static member properties

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cbc
Forum Newbie
Posts: 2
Joined: Mon Mar 09, 2009 9:38 am

Life and scope of static member properties

Post 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!
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Life and scope of static member properties

Post 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
cbc
Forum Newbie
Posts: 2
Joined: Mon Mar 09, 2009 9:38 am

Re: Life and scope of static member properties

Post 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
Post Reply