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]
|