php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #31766 printf and __toString
Submitted: 2005-01-30 20:57 UTC Modified: 2006-05-21 05:30 UTC
From: Robin at RHarmsen dot nl Assigned: Andi (profile)
Status: Closed Package: Feature/Change Request
PHP Version: 5.0.3 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: Robin at RHarmsen dot nl
New email:
PHP Version: OS:

 

 [2005-01-30 20:57 UTC] Robin at RHarmsen dot nl
Description:
------------
When having an object with an __toString() and using this object as a parameter in a printf the __toString isn't called

Reproduce code:
---------------
class User
{
  public $username;
  public function __toString()
  {
    return $username;
  }
}

$user = new User();
$user->username = "Test";
echo $this->user;
printf("Logged in as: %s\n",$this->user);



Expected result:
----------------
Test
Logged in as: Test

Actual result:
--------------
Test
Logged in as: Object id #1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-30 21:07 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

only echo and print call __toString()
 [2005-01-30 21:21 UTC] Robin at RHarmsen dot nl
I thought it also applyd to printf and sprintf
to bad :(
 [2005-01-30 22:56 UTC] helly@php.net
Actually this is a valid feature request and we said that we try to include this functionality in 5.1 once the inherent engine problems are solved.
 [2006-05-21 05:30 UTC] mfischer@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.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 15:01:34 2025 UTC