Re: Statics and PHP5
| From: | Dave Peckham | Date: | Mon, 16 Feb 2004 17:56:05 +0000 |
| Subject: | Re: Statics and PHP5 | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-7885@lists.php.net to get a copy of this message | ||
Jonathan,
Thanks for the reply. Actually, my question was not a
"how to use", but definitely a "what are you doing?"
intended for the PHP authors (i.e. the Zend folks).
Logging is a great example of what I'd like to do, but
won't work in the current PHP5 implementation. If you
write a Logger class as a singleton, and a page makes
10 calls to the logger, then sure, those 10 calls will
use the same instance of Logger. But if there are say
10 pages in a users' progression, then you'd get 10
singletons created just for that user (thereby not
actually being a singleton at all). And if there were
100 concurrent users, there would be 100*10 instances
of Logger created, 100 at the same time--definitely
not a singleton.
No other languages behave this way (not Java or C# for
sure).
Thanks for the pointer to that other framework.
Dave
--- Jonathan Arkell <jonny@sanriowasteland.net> wrote:
> Hi Dave
>
> I noticed your question on the php.internals mailing
> list, and I wasn't
> sure if you were going to get a reply because you
> were asking a quesiton
> about developing WITH php, rather then developing
> php itself, which is
> what the internals list is for.
>
> At any rate, the answer to your question is: You
> are correct, there
> classes are loaded and unloaded on each page
> request.
>
> There is actually quite a bit of use in static
> members, especially when
> you stop thinking in terms of page-requests, and
> more in terms of full
> blown web applications. Think of it this way, it's
> really nice to just
> have a logging singleton object (for instance) that
> you can
> getInstance(); of every time you need access to a
> logging object,
> instead of having to pass its reference around.
>
> However, there is a project that does what you want.
> SRM
> (http://www.vl-srm.net). It is a persistant object
> repository. Your
> Foo Class is defined and executed on the SRM server,
> and when your
> webserver gets a request, you write a little script
> to make a request
> for the Foo object from the SRM server. So the Foo
> objet is persisitant
> across requests.
> http://www.vl-srm.net/doc/design.graphic.php shows
> you
> what is going on here.
>
> Anyway, there you go, I hope that helps.
>
> --
> ,-------. The Cute Grim Floating Skull of
> Hello Cthulu Says
> / | | \
> / _ ^ _ \ Listen To Crazy Shaman Techno
> \_/ }|||{ \_/
> http://jonny.sanriowasteland.net
> '^"^`
> I'm Jonnay!
>
__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html