PHP5: using __CLASS__ within __toString in parent class

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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:

class SubClass extends Base
    // something

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

Is there a way to get around this?

TIA, Kjell

Re: PHP5: using __CLASS__ within __toString in parent class

Kjell Bublitz schreef:
Quoted text here. Click to load it

You can use get_class():


Site Timeline