Bug #67265 [Nab->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: Not a bug
+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:
Mike,
Generally we do not consider segfaults as acceptable behavior. Instead we need to fail nicely. This
*is* a bug.
Previous Comments:
------------------------------------------------------------------------
[2014-05-13 15:22:34] mike@php.net
Still, not a bug.
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
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)