Check if current function called statically or not

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

Comments

Popular posts from this blog

Install deb package via Termux

How to Make Blogger Safelink Converter v3

List of weapon buff materials, effects and how it can be durango wild lands