note 46210 deleted from language.oop5.magic by aidan

From: Date: Sat, 02 Oct 2004 19:33:05 +0000
Subject: note 46210 deleted from language.oop5.magic by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77759@lists.php.net to get a copy of this message
Note Submitter: zimba dot spam at gmail dot com ---- __toString() theorically permits to control the casting of your object to a string. Actually it only works with 'echo' <?php class ExampleClass { private $s = ''; function __construct($s) { $this->s = $s; } function __toString() { return $s; } } $x = new ExampleClass('woot'); $y = (string)$x; // casting echo $x; // gives 'woot'; echo $y; // gives 'Object #x' ?> IMO this should be also usable in casting. Also why not introduct magic methods for other types ? Cheers, zimba

« previous php.notes (#77759) next »