NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP5 Static Classes

Matt Juszczak matt at atopia.net
Mon Mar 7 17:00:22 EST 2005


OK, so I was reading this post and I have a feeling that my question can 
be answered as an ongoing continuation of this post.

I understand Object Oriented Programming in places such as a daemon, or 
when you're writing a game in java that constantly continues to run.

But I don't understand the use of Object Oriented Programming in 
scripting.  Once the page is loaded, a new instance of any object you've 
created must be re-created (unlike java where you can create a game and 
constantly interact with the same data set).

So my main question is:  Why do people use object oriented programming in 
websites?

Thanks! :)

-Matt

On Wed, 2 Feb 2005, Adam Maccabee Trachtenberg wrote:

> On Wed, 2 Feb 2005, Joseph Crawford wrote:
>
>> my question is how long will the object reside on the server though?
>
> You are confused. Static objects are constant within the request, but
> they do not persist between requests.
>
>> i understand that the object is the same for all users, but what if
>> the site has 0 users, does the object still exist? does it still
>> retain all the information?  when another visitor comes, does it
>> continue to use that instance or create a new instance
>
> A new instance. Here is a better way of thinking of static in an OO
> context. Static properties are similar to namespaced global variables;
> static methods are similar to namespaced functions.
>
> You can refer to them anywhere within a script without worrying that
> they might vary from instance to instance. (i.e. based on specific
> instance data.)
>
> You cannot set a value in one request and then access it in a second
> one. As Dan says, that's what a database is for.
>
> -adam
>
> -- 
> adam at trachtenberg.com | http://www.trachtenberg.com
> author of o'reilly's "upgrading to php 5" and "php cookbook"
> avoid the holiday rush, buy your copies today!
> _______________________________________________
> New York PHP Talk
> Supporting AMP Technology (Apache/MySQL/PHP)
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org
>
>
> !DSPAM:42015666650711093663439!
>



More information about the talk mailing list