note 29320 added to function.is-a

From: Date: Mon, 10 Feb 2003 01:17:38 +0000
Subject: note 29320 added to function.is-a
Groups: php.notes 
Request: Send a blank email to php-notes+get-43706@lists.php.net to get a copy of this message
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+) -- http://www.php.net/manual/en/function.is-a.php http://master.php.net/manage/user-notes.php?action=edit+29320 http://master.php.net/manage/user-notes.php?action=delete+29320 http://master.php.net/manage/user-notes.php?action=reject+29320

« previous php.notes (#43706) next »