#23312 [Com]: using objects as primitives (new magic function)
| From: | jevon at jevon dot org | Date: | Thu, 15 Apr 2004 02:55:12 +0000 |
| Subject: | #23312 [Com]: using objects as primitives (new magic function) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-58157@lists.php.net to get a copy of this message | ||
ID: 23312
Comment by: jevon at jevon dot org
Reported By: webmaster at s0nix dot de
Status: Open
Bug Type: Feature/Change Request
PHP Version: 5CVS-2003-04-23 (dev)
New Comment:
Doesn't __toString() do this already? (Although __toString()) is broken
at the moment.)
But along the same lines, how about a __toNumber() for arithmetic?
Previous Comments:
------------------------------------------------------------------------
[2003-04-23 02:18:15] webmaster at s0nix dot de
http://www.zend.com/phorum/read.php?num=6&id=668&loc=0&thread=668
[quote]
First, object representation in different contexts. Currently, if we
write:
echo $object;
PHP produce not much of information about instance: 'object'. I have
read many articles about new PHP5 features where I found note that we
will be able to use an object in a 'foreach' instruction, like an
array, if this object implement container interface. This is great - I
think about an another usage of this concept - using an object as a
string. For example, if class provide an specific method (magic
function?):
class TSerializable {
function __value() {
return $this->toXML();
}
}
we will be able to use it like a simple value - an object will be
automatically converted (with a method defined by the user) to a
'primitive' representation:
echo '<tag>'.$object.'</tag>';
or
<?=$object; ?>
This will be very useful - e.g. in serialization, debugging and
PHP-based templates because we will be able to use general syntax to
streaming simple and complex data.
[/quote]
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=23312&edit=1