If a method is static, you should only ever call it statically.
Doing any other tricks is just plain wrong.
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.

--Wez.

On Mon, 04 Oct 2004 13:01:56 +0100, Marcus Bointon
<[EMAIL PROTECTED]> wrote:
> How can you find out definitively if a method of a PHP class has been called
> statically, in both PHP 4 and 5? I'm aware of the way that $this behaves  -
> this is not that old FAQ, but it's at the root of the problem. I can't find
> a straight answer - even an "it's not possible" would be more helpful.
> 
> Just to illustrate:
> 
> Class a {
>   function foo(){
>     print "foo";
>   }
>   function spanner() {
>     a::foo();
>   }
> }
> Class b {
>   function bar() {
>     print "bar";
>   }
>   function foobar() {
>     a::foo();
>   }
>   function foobar2() {
>     $a = new a;
>     $a->foo();
>   }
> }
> 
> $a = new a;
> $b = new b;
> $a->foo(); //dynamic
> $b->bar(); //dynamic
> a::foo(); //static, $this undefined
> b::bar(); //static, $this undefined
> $b->foobar(); //statically calls a::foo()
> $b->foobar2(); //Dynamically calls a::foo()
> $a->spanner(); //Static call from an instance of itself
> 
> The problem is in detecting the last 3 call types correctly. You can't look
> at $this because it can't tell you anything useful about the call's context,
> unless it's undefined, in which case you know for sure that the call is
> static. Is_a() etc seem to be no use, as $this. It seems that there would be
> a place for an additional predefined variable like $me or something that
> does contain the current instance, if any, and avoids the transitive nature
> of $this.
> 
> I've asked this a couple of times on the general list, plus several forums,
> and aside from the usual pointers to the $this faq, no solution has been
> suggested, so I'm asking here.
> 
> This has been bugging me for ages, and I've been resorting to param counting
> to work around it for now - is there a better way?
> 
> Marcus
> --
> Marcus Bointon
> Synchromedia Limited: Putting you in the picture
> [EMAIL PROTECTED] | http://www.synchromedia.co.uk
> 
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to