Re: which class it is?
| From: | Jochem Maas | Date: | Fri, 04 Mar 2005 11:37:55 +0000 |
| Subject: | Re: which class it is? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-209969@lists.php.net to get a copy of this message | ||
anirudh dutt wrote:
On Fri, 4 Mar 2005 17:41:01 +0800, yangshiqi <yangshiqi@3721.com> wrote:if you are using the 'public' keyword then you have to use php5,.....class DebugHelper {create a debug function (public) and use get_class. call that in thevar $_str; function do($string) ( //here I want to know which class called this function do totrace the bug.$this->_str .= $string; ) function show() { return $this->_str; }} class B {function B() { $debug = &new DebugHelper; $debug->do('here'); ... }}
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 useif you're using php5 all objects are references, pass-by-reference occurs whether you like it or not (unless you specifically use 'clone') ...also a constant (global or class scope) cannot be set to an object. I'm still very curious as to how Yangshiqi intends to use his DebugHelper class! (apologies if I have written your name incorrectly.)
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]