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:
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: iceberg dot young at gmail dot com
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2017 The PHP Group
All rights reserved.
Last updated: Tue Mar 28 00:01:34 2017 UTC