Re: Why does PHP have __toString() and not just toString()

From: Date: Tue, 12 Apr 2005 09:27:34 +0000
Subject: Re: Why does PHP have __toString() and not just toString()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-212895@lists.php.net to get a copy of this message
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

« previous php.general (#212895) next »