Re: which class it is?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



anirudh dutt wrote:
On Fri, 4 Mar 2005 17:41:01 +0800, yangshiqi <yangshiqi@xxxxxxxx> 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

if you are using the 'public' keyword then you have to use php5,.....

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

if 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]


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux