Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13135 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58013 invoked by uid 1010); 4 Oct 2004 12:12:51 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 57944 invoked from network); 4 Oct 2004 12:12:50 -0000 Received: from unknown (HELO mproxy.gmail.com) (216.239.56.246) by pb1.pair.com with SMTP; 4 Oct 2004 12:12:50 -0000 Received: by mproxy.gmail.com with SMTP id w67so357325cwb for ; Mon, 04 Oct 2004 05:12:49 -0700 (PDT) Received: by 10.11.119.54 with SMTP id r54mr1237766cwc; Mon, 04 Oct 2004 05:12:49 -0700 (PDT) Received: by 10.11.117.13 with HTTP; Mon, 4 Oct 2004 05:12:49 -0700 (PDT) Message-ID: <4e89b426041004051225c86945@mail.gmail.com> Date: Mon, 4 Oct 2004 13:12:49 +0100 Reply-To: Wez Furlong To: Marcus Bointon Cc: PHP internals In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: Subject: Re: [PHP-DEV] Static call detection From: kingwez@gmail.com (Wez Furlong) 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 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 > marcus@synchromedia.co.uk | http://www.synchromedia.co.uk > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >