By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,642 Members | 1,687 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,642 IT Pros & Developers. It's quick & easy.

PHP5: using __CLASS__ within __toString in parent class

P: n/a
Hi all

I have a little problem. The method __toString() inherits as expected
on all sub-classes but the __CLASS__ constant returns only the name of
the parent class where the method is defined.

class Base {
public function __toString()
{
return 'Type: '.__CLASS__.', Class: '.$this->name.' (Level:
'.$this->level.')';
}
}

class SubClass extends Base
{
// something
}

$obj = new SubClass();
echo $obj; // -displays "Base"

Is there a way to get around this?

TIA, Kjell

Jan 26 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Kjell Bublitz schreef:
$obj = new SubClass();
echo $obj; // -displays "Base"

Is there a way to get around this?
You can use get_class():

http://www.php.net/get_class
JW
Jan 26 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.