php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #23312 using objects as primitives (new magic function)
Submitted: 2003-04-23 02:18 UTC Modified: 2004-04-15 03:30 UTC
From: webmaster at s0nix dot de Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5CVS-2003-04-23 (dev) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
32 + 24 = ?
Subscribe to this entry?

 
 [2003-04-23 02:18 UTC] 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]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-14 22:55 UTC] jevon at jevon dot org
Doesn't __toString() do this already? (Although __toString()) is broken at the moment.)

But along the same lines, how about a __toNumber() for arithmetic?
 [2004-04-15 03:30 UTC] derick@php.net
No more magic, please.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 04:01:31 2024 UTC