note 46210 added to language.oop5.magic
| From: | zimba dot spam at gmail dot com | Date: | Sat, 02 Oct 2004 13:43:35 +0000 |
| Subject: | note 46210 added to language.oop5.magic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-77741@lists.php.net to get a copy of this message | ||
__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
----
Manual Page -- http://www.php.net/manual/en/language.oop5.magic.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46210
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46210&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46210&report=yes
Search -- http://master.php.net/manage/user-notes.php