You are here: Re: [PHP] Why does PHP have __toString() and not just toString() « PHP « IT news, forums, messages
Re: [PHP] Why does PHP have __toString() and not just toString()

Posted by Rory Browne on 04/12/05 14:27

I was wondering that as well. While I was at it, I wondered why not
use __to_str(), as per the PHP coding guidelines.

While I'm at it, why is grass green, and milk white?

On Apr 12, 2005 10:27 AM, Richard Davey <rich@launchcode.co.uk> wrote:
> Hello Tim,
>
> Tuesday, April 12, 2005, 10:07:44 AM, you wrote:
>
> TB> I'm wondering, why does the toString() of classes have two underscored
> TB> preceding it [e.g. __toString()], as opposed to Java's normal toString()?
>
> TB> What's the purpose of the two underscores in PHP's classes?
>
> The short answer: Because PHP isn't Java.
>
> The long answer: Two underscores denote what PHP refers to as a "magic
> method". You shouldn't have your own functions with the same names
> (unless you require that magical functionality). Have a look in the
> PHP manual under the "Magic Methods" section for more info / examples.
>
> Best regards,
>
> Richard Davey
> --
> http://www.launchcode.co.uk - PHP Development Services
> "I do not fear computers. I fear the lack of them." - Isaac Asimov
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

 

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

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