note 29320 deleted from function.is-a by nlopess
| From: | nlopess@php.net | Date: | Fri, 09 Apr 2004 14:30:28 +0000 |
| Subject: | note 29320 deleted from function.is-a by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-67897@lists.php.net to get a copy of this message | ||
Note Submitter: hendrix at zervaas dot info
----
This snippet determines if a class method has been called statically, or applied to an object.
That is:
$obj = new MyClass();
$obj->method();
- or -
MyClass::method()
To differentiate, you could use:
class MyClass {
function method()
{
if (is_a($this, 'MyClass')) {
// called as $obj->method()
}
else {
// called as MyClass::method()
}
}
}
Note: you could use __CLASS__ in the is_a() call instead of 'MyClass' if you have a new
enough version of PHP (4.3.0+)