Re: Re: Preventing static method calls in PHP4
| From: | Justin Patrin | Date: | Thu, 22 Jul 2004 16:45:45 +0000 |
| Subject: | Re: Re: Preventing static method calls in PHP4 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-191541@lists.php.net to get a copy of this message | ||
On Thu, 22 Jul 2004 11:26:44 +0100, Marcus Bointon
<marcus@synchromedia.co.uk> wrote:
> on 22/7/04 10:49, Jason Barnett at jasbarne@indiana.edu wrote:
>
> > The easiest way I can think of to prevent static method calls is to use the
> > $this pseudo variable in your method. A method *cannot* be used statically if
> > the method requires use of $this.
>
> Unfortunately that doesn't work - it is exactly the case that fails in my
> example. $this IS set in a static method that's called from any object
> instance (even one of a different class), and it's a PHP feature, not a bug.
>
If $this is set, check to see if it's of the type of the class the
static method is in. If it is, then it's not a static call.
This can be confusing because you can call methods in the current
class with the same syntax as static calls.
class A {
function b() {
}
function c() {
//this is not a static call as it's in the current class
A::b();
}
}
class B {
function c() {
//also not a static call, just forcing use of the A's c
A::c():
}
}
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--