You are here: Re: Operator Overloading « PHP Programming Language « IT news, forums, messages
Re: Operator Overloading

Posted by Richard Levasseur on 07/14/06 17:48

deciacco wrote:
> I was wondering if there was a way to do operator overlaoding in php
> like you can in c++.
>
> In c++ you can do something like:
>
> cout << myobject; -- and have myobject handle the output.
>
> Is there a way to...
>
> echo myobject; -- and be able to have a custom definded method in
> myobject do some kind of output?
>
> Any other suggestions?
> ( I was thinking of having a custom method called echo in myobject so
> one could do echo myobject->echo(); This is not as clean....)
>
> Thanks!!

Use the magic method __toString(). Note: it is only invoked when
directly printed. echo "$myobj" will not invoke __toString()

See http://us2.php.net/manual/en/language.oop5.php for more info about
PHP5 objects

 

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

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