Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13134 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30793 invoked by uid 1010); 4 Oct 2004 12:01:58 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 30677 invoked from network); 4 Oct 2004 12:01:58 -0000 Received: from unknown (HELO smtp.bulldogdsl.com) (212.158.192.11) by pb1.pair.com with SMTP; 4 Oct 2004 12:01:58 -0000 Received: from [10.0.0.1] (host-212-158-205-94.bulldogdsl.com [212.158.205.94]) by smtp.bulldogdsl.com (Postfix) with ESMTP id 85288FD8D for ; Mon, 4 Oct 2004 13:01:57 +0100 (BST) User-Agent: Microsoft-Entourage/10.1.4.030702.0 Date: Mon, 04 Oct 2004 13:01:56 +0100 To: PHP internals Message-ID: Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit Subject: Static call detection From: marcus@synchromedia.co.uk (Marcus Bointon) 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