Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:11461 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31413 invoked by uid 1010); 22 Jul 2004 08:27:34 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 31387 invoked from network); 22 Jul 2004 08:27:33 -0000 Received: from unknown (HELO smtp.bulldogdsl.com) (212.158.192.11) by pb1.pair.com with SMTP; 22 Jul 2004 08:27:33 -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 14725FE63 for ; Thu, 22 Jul 2004 09:27:33 +0100 (BST) User-Agent: Microsoft-Entourage/10.1.4.030702.0 Date: Thu, 22 Jul 2004 09:27:31 +0100 To: PHP internals Message-ID: Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit Subject: How to tell if a method is called statically in PHP4? From: marcus@synchromedia.co.uk (Marcus Bointon) Apologies for posting this here, but I can't find a documented solution for this and PHP-General has not provided any ideas. I'm wondering if it's even possible. Anotstatic = true; } function dynamic() { if (!isset($this) or !is_a($this, 'A') or !(isset($this->Anotstatic) and $this->Anotstatic)) echo "Method called statically\n"; else echo "dynamic-only function\n"; } function test () { A::dynamic(); //How to stop this working? } } class B { function test() { A::dynamic(); } } $a = new A(); $a->dynamic(); //Passes, dynamic call allowed A::dynamic(); //Passes, static call prevented $b = new B; $b->test(); //Passes, static call prevented $a->test(); //Fails, static call allowed ?> This works for the first 3 tests (so I'm getting there), but not the fourth, that is a dynamic method being called statically from an instance of the same class. Is there something I've missed that will allow me to intercept this style of call? I know that this problem goes away in PHP5, and that the setting of $this in static calls from other instances is not a bug (though it's at the root of this problem). Is there some other property like $this that doesn't have this behaviour? Many thanks for any suggestions, Marcus -- Marcus Bointon Synchromedia Limited: Putting you in the picture marcus@synchromedia.co.uk | http://www.synchromedia.co.uk