Determining if a method was called statically

Posted on

In PHP, it’s occasionally helpful to call a method sometimes statically and sometimes from class instance. Figuring out which way a method has been called is pretty straightforward, thanks to a function posted in the PHP documentation:

<?php
function foo () {
$isStatic = !(isset($this) && get_class($this) == __CLASS__);
}
?>

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s