pre>
static = issetthis amp;amp; get_classthis == __CLASS__;
if static
return self;
else
in class example:
$static = !(isset($this) && get_class($this) == __CLASS__);
if ($static) {
return self;
} else {
return $this;
}
class Foo {or simply create below function to test:
function bar() {
$static = !(isset($this) && get_class($this) == __CLASS__);
if ($static) {
return self;
} else {
return $this;
}
}
}
How do I check in PHP that I'm in a static context (or not)?
class A
{
function foo()
{
if (isset($this)) {
echo '$this is defined (';
echo get_class($this);
echo ")\n";
} else {
echo "\$this is not defined.\n";
}
}
}