Bug #67265 [Nab]: Segmentation fault on json_encode with json_serializable
| From: | edu at offerum dot com | Date: | Wed, 14 May 2014 14:44:36 +0000 |
| Subject: | Bug #67265 [Nab]: Segmentation fault on json_encode with json_serializable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185822@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67265&edit=1
ID: 67265
User updated by: edu at offerum dot com
Reported by: edu at offerum dot com
Summary: Segmentation fault on json_encode with
json_serializable
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:
Just to clarify, It wasn't my intention to reopen the bug yesterday; it happend that Mike
closed the bug while I was writing my comment, so I reopened it without knowing it :)
Once I know why this happens, it's not a problem for me. But initially it wasn't so
obvious that returning an instance of the object itself wasn't a good idea. Maybe a warning
note in documentation about potential recursivity problems would be a good idea.
Anyway, at least here is this bug so other people can find it if they're facing the same
problem.
Previous Comments:
------------------------------------------------------------------------
[2014-05-13 19:44:37] tyrael@php.net
while I agree that this isn't nice, but we have a bunch of other cases when infinite recursion
will result in a segfault (for example http://3v4l.org/uhInN),
and mike is right about that we close these kind of reports as not a bug/won't fix, for example
https://bugs.php.net/bug.php?id=51350 or https://bugs.php.net/bug.php?id=64280
We even had a pull request which could have fixed some of those cases
(https://github.com/php/php-src/pull/290) but it was declined as something we don't need in the
core.
If you think it is worth your time, please bring this up on the internals mailing list so maybe we
can make a different agreement this time.
------------------------------------------------------------------------
[2014-05-13 15:29:30] levim@php.net
Mike,
Generally we do not consider segfaults as acceptable behavior. Instead we need to fail nicely. This
*is* a bug.
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
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