]> granicus.if.org Git - php/commitdiff
- MFH: Fixed bug #46215 (json_encode mutates its parameter and has some class-specifi...
authorFelipe Pena <felipe@php.net>
Thu, 2 Oct 2008 03:41:24 +0000 (03:41 +0000)
committerFelipe Pena <felipe@php.net>
Thu, 2 Oct 2008 03:41:24 +0000 (03:41 +0000)
NEWS
ext/json/json.c
ext/json/tests/bug46215.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 9e7df06cf2abb43194a32952aa623694d6692a71..33c1832554173afdf268ef36bed03078f3d9c800 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,10 +18,12 @@ PHP                                                                        NEWS
   (Scott)
 - Fixed a crash on invalid method in ReflectionParameter constructor.
   (Christian Seiler)
+- Fixed bug #46215 (json_encode mutates its parameter and has some 
+  class-specific state). (Felipe)
 - Fixed bug #46191 (BC break: DOMDocument saveXML() doesn't accept null). (Rob)
 - Fixed bug #46157 (PDOStatement::fetchObject prototype error). (Felipe)
-- Fixed bug #46147 (after stream seek, appending stream filter reads incorrect data).
-  (Greg)
+- Fixed bug #46147 (after stream seek, appending stream filter reads 
+  incorrect data). (Greg)
 - Fixed bug #46088 (RegexIterator::accept - segfault). (Felipe)
 - Fixed bug #46059 (Compile failure under IRIX 6.5.30 building posix.c). 
   (Arnaud)
index 40942a9b7cb471deebc700fd88521ac2d86f0496..4c1a57d33054b860290973ae3057d3e54a6fdc33 100644 (file)
@@ -181,6 +181,9 @@ static void json_encode_array(smart_str *buf, zval **val TSRMLS_DC) { /* {{{ */
                     if (i == HASH_KEY_IS_STRING) {
                         if (key[0] == '\0' && Z_TYPE_PP(val) == IS_OBJECT) {
                             /* Skip protected and private members. */
+                                                       if (tmp_ht) {
+                                                               tmp_ht->nApplyCount--;
+                                                       }
                             continue;
                         }
 
diff --git a/ext/json/tests/bug46215.phpt b/ext/json/tests/bug46215.phpt
new file mode 100644 (file)
index 0000000..da3344f
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Bug #46215 (json_encode mutates its parameter and has some class-specific state)
+--FILE--
+<?php
+
+class foo {
+    protected $a = array();
+}
+
+$a = new foo;
+$x = json_encode($a);
+
+print_r($a);
+
+?>
+--EXPECT--
+foo Object
+(
+    [a:protected] => Array
+        (
+        )
+
+)