php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #37702 Make toString working with strval
Submitted: 2006-06-05 15:29 UTC Modified: 2006-08-12 16:10 UTC
From: php at bouchery dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.1.* OS: *
Private report: No CVE-ID: None
 [2006-06-05 15:29 UTC] php at bouchery dot com
Description:
------------
Currently, __toString work ONLY with echo/print, and it's very restrictive.

It could be very interresting to allow toString working with strval() to avoid this :

<?php
if( is_object($var) ) $text = 'var = ' . $var->__toString();
else $text = 'var = ' . $var;
?>

Expected result:
----------------
<?php
$text = 'var = ' . strval($var);
?>

Or better :

<?php
$text = 'var = ' . $var;
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-05 15:34 UTC] helly@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Cannot be fixed in 5.1 and is already fixed in HEAD and 5.2
 [2006-06-05 18:46 UTC] php at bouchery dot com
It's a bug ?

Seen in the documentation : 
"It is worth noting that the __toString method will only be called when it is directly combined with echo() or print()."

And Example 19-28 confirm this "feature".

here : http://www.php.net/manual/en/language.oop5.magic.php
 [2006-06-05 20:34 UTC] derick@php.net
Opening this as a doc problem then, as it needs to be documented that it will work in 5.2 ofcourse.
 [2006-08-12 16:10 UTC] nlopess@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:11 UTC] phpdocbot@php.net
Automatic comment on behalf of nlopess
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=ca562b60e8fcd724a0ed2758c898911805eff2d4
Log: fix #37702: __toString() is now more magical since php 5.2
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 13:01:36 2025 UTC