Re: which class it is?

From: Date: Fri, 04 Mar 2005 11:29:13 +0000
Subject: Re: which class it is?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-209968@lists.php.net to get a copy of this message
On Fri, 4 Mar 2005 17:41:01 +0800, yangshiqi <yangshiqi@3721.com> wrote: > class DebugHelper > { > var $_str; > function do($string) > ( > //here I want to know which class called this function do to > trace the bug. > $this->_str .= $string; > ) > function show() > { > return $this->_str; > } > } > > class B > { > function B() > { > $debug = &new DebugHelper; > $debug->do('here'); > ... > } > } create a debug function (public) and use get_class. call that in the debug function. when u want to do the debugging, use it with the obj as parameter, maybe $this will work when u're in the class, otherwise, use the object aka class instance variable. u may wanna pass by reference and make it const (won't have to use more memory for it...since it's task with it is small and read-only) from http://php.net/get_class [quote] Example 1. Using get_class() <?php class foo { function foo() { // implements some logic } function name() { echo "My name is " , get_class($this) , "\n"; } } // create an object $bar = new foo(); // external call echo "Its name is " , get_class($bar) , "\n"; // internal call $bar->name(); ?> The above example will output: Its name is foo My name is foo [/quote] -- ]# Anirudh Dutt ...pilot of the storm who leaves no trace like thoughts inside a dream

« previous php.general (#209968) next »