Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Operator Overloading
July 14, 2006, 4:17 pm
rate this thread
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....)
Re: Operator Overloading
Richard is correct define a function called __toString() in your class
without whatever class variables you want to print off. Notice that
there are 2 underscores on __toString()
You might want to consider an excellent book called PHP 5 Objects,
Patterns, and Practice... I'm reading it now and it covers many of
PHP's advancent features including OO and design patterns.
- » "call to undefined function" mysql_error when adding new rows to table
- — Previous thread in » PHP Scripting Forum