Bug #67265 [Opn]: Segmentation fault on json_encode with json_serializable
Edit report at https://bugs.php.net/bug.php?id=67265&edit=1
ID: 67265
Updated by: levim@php.net
Reported by: edu at offerum dot com
Summary: Segmentation fault on json_encode with
json_serializable
Status: Open
Type: Bug
Package: JSON related
Operating System: Linux (Ubuntu 14.04)
PHP Version: 5.5.12
Block user comment: N
Private report: N
New Comment:
Glancing at the backtrace on my local machine this has to do with clone call.
Previous Comments:
------------------------------------------------------------------------
[2014-05-13 14:09:16] edu at offerum dot com
Description:
------------
php-cgi segfaults when trying to encode a class which extends json_serializable.
At least this happens when the json_serialize method unsets a variable declared in the class.
Example in:
http://3v4l.org/TSgMV
---
From manual page: http://www.php.net/class.jsonserializable
---
Test script:
---------------
class C implements JsonSerializable {
var $a = 'lol';
var $b = 'fa';
public function jsonSerialize() {
$aux = clone($this);
unset($aux->a);
return $aux;
}
}
echo json_encode(new C()); //Ka-boom!!
Expected result:
----------------
The object json-encoded only with var $b.
Actual result:
--------------
Segmentation fault.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67265&edit=1
Thread (10 messages)