NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP5 Static Classes

Adam Maccabee Trachtenberg adam at trachtenberg.com
Wed Feb 2 17:38:25 EST 2005


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!



More information about the talk mailing list
Automatic Email Organization without missing anything!