![]() |
Magic Function: __toString()
For this article we’ll be looking at the __toString magic function, and a very handy function it is to. What this function does is allow you to change the default behaviour when outputting an object instance. Consider we had the following class:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
If we were to now execute the script again, this time, we would see the following output: PHP Code:
PHP Code:
PHP Code:
|
Wow, sounds awesome!
Didn't get the $aMembers though.. where did that come from? |
Quote:
Useful guide, thanks Karl. |
Yea, I got that.. but how would he get it.. hypotheticly?
|
The
$aMembers array in Karl's article could have come from anywhere, a database or hard-coded for example.PHP Code:
|
it is really very useful.
|
Found this tutorial (found it AGAIN so to speak) when I was browsing Tutorialized.com.
As an explanation to Tanax, foreach ($key as $value), $key is being 'stuffed' into $value. :-) |
| All times are GMT. The time now is 08:51 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0