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.
<?php
class A {
var $Anotstatic;
function A() {
$this->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