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)?

0 Response to "Check if current function called statically or not"

Post a Comment

Bila Ada posting yang kurang, atau error atau yang lainnya, silahkan tinggalkan komentar agar artikel/post di perbaiki.
Jangan Lupa Cek Box "Notify Me" agar tahu komentar kamu dibalas oleh saya.

If there are any posts that are missing, or error or anything else, please leave a comment for the article / post to be fixed.
Do not Forget Check Box "Notify Me" to know our comments replied by me.

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel