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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: webmaster at s0nix dot de
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Thu Dec 26 10:01:29 2024 UTC