Bug #81524 [NEW]: json_encode() on JsonSerializable populates the properties HashTable

From: Date: Wed, 13 Oct 2021 22:54:46 +0000
Subject: Bug #81524 [NEW]: json_encode() on JsonSerializable populates the properties HashTable
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237187@lists.php.net to get a copy of this message
From: tstarling Operating system: PHP version: 8.1Git-2021-10-13 (Git) Package: JSON related Bug Type: Bug Bug description:json_encode() on JsonSerializable populates the properties HashTable Description: ------------ I noticed that if you do json_encode() on a JsonSerializable object, it always populates the properties hashtable, because php_json_encode_serializable_object() needs a hashtable to have somewhere to set the recursion flag. You might think it could just set the recursion flag on the object, but a few test cases (and probably users) do var_dump($this) in jsonSerialize(), which breaks if you protect the object prior to calling jsonSerialize(). It's possible to solve this by adding a second recursion flag to gc_flags, but that's a bit of a joke solution since I wouldn't expect a PR which consumes a bit in gc_flags to be accepted. But here it is if you're curious: https://github.com/tstarling/php-src/commit/1e975dfa731ceba4533aea0efdbd803d226963c9 -- Edit bug report at https://bugs.php.net/bug.php?id=81524&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=81524&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=81524&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=81524&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=81524&r=needscript Try newer version: https://bugs.php.net/fix.php?id=81524&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=81524&r=support Expected behavior: https://bugs.php.net/fix.php?id=81524&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=81524&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=81524&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=81524&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=81524&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=81524&r=dst IIS Stability: https://bugs.php.net/fix.php?id=81524&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=81524&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=81524&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=81524&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=81524&r=mysqlcfg

« previous php.bugs (#237187) next »