You are here: Re: [PHP] which class it is? « PHP « IT news, forums, messages
Re: [PHP] which class it is?

Posted by Anirudh Dutt on 03/04/05 13:29

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация