2012/9/27 Yves Goergen <nospam.l...@unclassified.de>

> On 26.09.2012 23:38 CE(S)T, Stuart Dallas wrote:
> > On 26 Sep 2012, at 22:29, Yves Goergen <nospam.l...@unclassified.de>
> > wrote:
> >> My class is a debug helper class, that can write trace messages and
> >> so on. I have added a random per-request tag to distinguish
> >> concurrent requests in the trace file and thought that generating
> >> such a tag would perfectly fit in a static constructor. Now a
> >> helper function does that check and generates one on the first call
> >> of the method.
> >
> > I would strongly recommend a singleton, or if you must use a static
> > class you can either use the initialisation mechanism I described or,
> > if the class has a single method as I'm guessing, have that method
> > check the static variable to see if it's been set yet, and if not
> > generate it before doing anything else.
>
> Why does everybody seem to recommend singletons so strongly? What's
> wrong with static classes? Are they considered as "global variables",
> the most evil remainder from the Middle Age? What is easier to call on a
> regular hacky basis:
>
> XyzDebug::Trace(...);
>
> or
>
> XyzDebug::GetInstance()->Trace(...);
>

Or just

    XyzDebug\trace();

Functions are not dead yet


>
> I really prefer the first one. I always use static classes when there is
> no real instance of something. Why should I force to act as if, only to
> follow some trendy pattern?
>
> --
> Yves Goergen - nospam.l...@unclassified.de - http://unclassified.de
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
github.com/KingCrunch

Reply via email to