|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-05-13 14:09 UTC] 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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 23:00:02 2025 UTC |
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