Re: which class it is?

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

 



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

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