Re: Static call detection
| From: | Wez Furlong | Date: | Mon, 04 Oct 2004 13:09:37 +0000 |
| Subject: | Re: Static call detection | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-13137@lists.php.net to get a copy of this message | ||
I was asked off-list by someone else why I thought it was wrong, it
turns out that I wasn't as clear as I could have been, so I'm going to
follow up here and then withdraw (because I don't consider it an
internals matter).
It *is* ok to have a static method and call it either statically or
not, provided that the method still behave statically (eg: the same)
in both contexts.
It is *not* ok to have a static method try and work like a non static method.
In PHP 5, declaring a static method will prevent $this from being initialized.
static means static. Take this as a hint that what you're trying to
do it wrong :-)
If you want to hack around the guts and do unsupported stuff like
this, be prepared for your code to break in future versions of PHP.
*cough* gallery assigning to $this *cough*
--Wez.
On Mon, 04 Oct 2004 14:34:36 +0200, Christian Schneider
<cschneid@cschneid.com> wrote:
> Wez Furlong wrote:
> > If a method is static, you should only ever call it statically.
> > Doing any other tricks is just plain wrong.
>
> I dare to disagree. For tool functions it often makes sense to make them
> statically callable while you still might want to use them in an object
> instance context respecting the instance's state. It may seem a bit
> hacky but I like PHP for being dynamic enough to allow this.
>
> Different people use different styles and I wouldn't say "Using
> exceptions is just plain wrong" even though I don't like them ;-)
>
> > If you still want to know the answer, ask the question on the correct
> > list; what you've asked has nothing to do with hacking on the
> > internals of PHP in C.
>
> He is asking for a mechanism to properly determine the static/non-static
> status of a call and I assume he also suggests to add such a mechanism
> in case it doesn't exist so I think your answer should be less hostile
> as it concerns internals IMHO.