You are here: PHP5: using __CLASS__ within __toString in parent class « PHP Programming Language « IT news, forums, messages
PHP5: using __CLASS__ within __toString in parent class

Posted by Kjell Bublitz on 01/26/07 06:25

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

 

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

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