Bug #67265 [Opn->Nab]: 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: mike@php.net
Reported by: edu at offerum dot com
Summary: Segmentation fault on json_encode with
json_serializable
-Status: Open
+Status: Not a bug
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:
Still, not a bug.
Previous Comments:
------------------------------------------------------------------------
[2014-05-13 15:21:14] edu at offerum dot com
Yep, I was wrong thinking it has something to do with deleting object variables.
Indeed, the behaviour can be seen pretty clear here:
class C implements JsonSerializable {
public function jsonSerialize() {
$a = clone($this);
echo 1;
return $a;
}
}
echo json_encode(new C());
Example:
http://3v4l.org/nRMRj
------------------------------------------------------------------------
[2014-05-13 15:19:26] mike@php.net
Yep. This is not a bug but infinite recursion.
------------------------------------------------------------------------
[2014-05-13 15:18:08] levim@php.net
My $0.02; find some way to protect against recursion and then fail nicely.
------------------------------------------------------------------------
[2014-05-13 15:14:46] levim@php.net
Additionally, the code is recursively calling jsonSerialize; you need to return an array.
------------------------------------------------------------------------
[2014-05-13 15:12:52] levim@php.net
Glancing at the backtrace on my local machine this has to do with clone call.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=67265
--
Edit this bug report at https://bugs.php.net/bug.php?id=67265&edit=1
Thread (10 messages)