php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32696 (stirng)cast breaks __toString() for exceptions
Submitted: 2005-04-13 16:29 UTC Modified: 2005-04-13 16:50 UTC
From: ilia@php.net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2005-04-13 (dev) OS: ANY
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: ilia@php.net
New email:
PHP Version: OS:

 

 [2005-04-13 16:29 UTC] ilia@php.net
Description:
------------
Adding (string) cast to an exception object on output causes PHP to output the object identifier rather then executing __toString() and printing the defined text.

Removing the (string) cast on output makes the desired behaviour occur (print "Test 123").

Reproduce code:
---------------
<?php
class E extends Exception {
        public function __toString() {
                return "Test 123";
        }
}
try {
        throw new E();
} catch (E $e) {
        echo (string) $e;
}
?>

Expected result:
----------------
Test 123

Actual result:
--------------
Object id #1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-13 16:50 UTC] iliaa@php.net
not a bug, although a rather unusual situation.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 23:01:33 2025 UTC