note 48607 added to function.is-object

From: Date: Sat, 01 Jan 2005 15:47:56 +0000
Subject: note 48607 added to function.is-object
Groups: php.notes 
Request: Send a blank email to php-notes+get-82540@lists.php.net to get a copy of this message
You can use is_object($this) to detect if the function is being called via instance or procedure. Example: <?php class mrClass { function test( ) { if( is_object($this) ) { // do something for instance method echo 'this is an instance call <br />' . "\n"; } else { // do something different for procedural method echo 'this is a procedure call <br />' . "\n"; } } } $inst = new mrClass(); $inst->test(); mrClass::test(); ?> This would output: this is an instance call <br /> this is a procedure call <br /> :-) Happy coding! ---- Manual Page -- http://www.php.net/manual/en/function.is-object.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48607 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48607&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48607&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48607&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48607&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48607&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48607&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48607&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82540) next »