
Check if current function called statically or not
2019-12-03 / Dimas Lanjaka Kumala Indra
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";
}
}
}

Check if current function called statically or not
PermaLink: https://www.webmanajemen.com/2019/12/check-if-current-function-called.html
Google Rich Snippets | Schema Markup Validator | Google Pagespeed Insight