php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73350 Exception::__toString() cause circular references
Submitted: 2016-10-19 15:01 UTC Modified: 2016-10-19 16:54 UTC
From: iceberg dot young at gmail dot com Assigned:
Status: Closed Package: *Programming Data Structures
PHP Version: 7.0.12 OS: CentOS 6/7; openSUSE Leap
Private report: No CVE-ID: None
 [2016-10-19 15:01 UTC] iceberg dot young at gmail dot com
Description:
------------
Exception::__toString() method will cause circular references.
And therefore breaks some *array* related functions.

Version 7.0.11 is fine.

Tested on CentOS 6/7 x64, packages from
 http://rpms.famillecollet.com/enterprise/{6,7}/php70/x86_64/repoview/

Tested on openSUSE Leap 42.1 x64, packages from
 http://download.opensuse.org/repositories/devel:/languages:/php/openSUSE_Leap_42.1/

Test script:
---------------
<?php
$e = new Exception();

// This line cause problem :(
// Comment it to see the difference.
(string) $e;

// This line show the clue (PHP Warning: ...).
var_export($e);

// This line will be affected.
var_export(json_encode([$e]));

// But This line still OK.
var_export(json_encode($e));


Expected result:
----------------
# var_export($e)
Exception::__set_state(array(
   'message' => '',
   'string' => '',
   'code' => 0,
   'file' => 'demo.php',
   'line' => 2,
   'trace' => 
  array (
  ),
   'previous' => NULL,
))

# var_export(json_encode([$e]))
'[{}]'

# var_export(json_encode($e))
'{}'


Actual result:
--------------
# var_export($e)
PHP Warning:  var_export does not handle circular references in demo.php on line 9
NULL

# var_export(json_encode([$e]))
false

# var_export(json_encode($e))
'{}'


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-19 16:54 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2016-10-19 16:54 UTC] cmb@php.net
Confirmed: <https://3v4l.org/F49vv> vs. <https://3v4l.org/Lgvq6>.
 [2016-10-22 06:53 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=eca84946a4e7269d59ea2d79b5f42117de89ae74
Log: Fixed bug #73350 (Exception::__toString() cause circular references)
 [2016-10-22 06:54 UTC] laruence@php.net
-Status: Verified +Status: Closed
 [2016-10-25 15:21 UTC] krakjoe@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=eca84946a4e7269d59ea2d79b5f42117de89ae74
Log: Fixed bug #73350 (Exception::__toString() cause circular references)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 13 14:01:27 2024 UTC