]> granicus.if.org Git - php/commitdiff
Fixed bug #30791 (magic methods (__sleep/__wakeup/__toString) call __call if object...
authorDmitry Stogov <dmitry@php.net>
Wed, 1 Jun 2005 10:53:57 +0000 (10:53 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 1 Jun 2005 10:53:57 +0000 (10:53 +0000)
NEWS
Zend/tests/bug30791.phpt [new file with mode: 0755]
Zend/zend_object_handlers.c
ext/standard/var.c
ext/standard/var_unserializer.c
ext/standard/var_unserializer.re

diff --git a/NEWS b/NEWS
index 81c234e0695f4593a3ef05175deeb6ce3c82f79a..eb3438006c00b21ea6a05f216a42013bff069f92 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -111,6 +111,8 @@ PHP                                                                        NEWS
 - Fixed bug #30889 (Conflict between __get/__set and ++ operator). (Dmitry)
 - Fixed bug #30833 (array_count_values() modifying input array). (Tony)
 - Fixed bug #30819 (Better support for LDAP SASL bind). (Jani)
+- Fixed bug #30791 (magic methods (__sleep/__wakeup/__toString) call __call if
+  object is overloaded). (Dmitry)
 - Fixed bug #30707 (Segmentation fault on exception in method). (Stas, Dmitry)
 - Fixed bug #30702 (cannot initialize class variable from class constant).
   (Dmitry)
diff --git a/Zend/tests/bug30791.phpt b/Zend/tests/bug30791.phpt
new file mode 100755 (executable)
index 0000000..f56bcfb
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Bug #30791 magic methods (__sleep/__wakeup/__toString) call __call if object is overloaded 
+--FILE--
+<?php
+class a {
+   public $a = 4;
+   function __call($a,$b) {
+       return "unknown method";
+   }
+}
+$b = new a;
+echo $b,"\n";
+$c = unserialize(serialize($b));
+echo $c,"\n";
+var_dump($c);
+?>
+--EXPECT--
+Object id #1
+Object id #2
+object(a)#2 (1) {
+  ["a"]=>
+  int(4)
+}
index c1b134d15b41499dc743d80956ceee61ddde1479..2886d1c7f42547275d6ab367d0305195a74bccd7 100644 (file)
@@ -954,6 +954,9 @@ ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int ty
        
        switch (type) {
                case IS_STRING:
+                       if (!zend_hash_exists(&Z_OBJCE_P(readobj)->function_table, "__tostring", sizeof("__tostring"))) {
+                               return FAILURE;
+                       }
                        ZVAL_STRING(&fname, "__tostring", 0);
                        if (call_user_function_ex(NULL, &readobj, &fname, &retval, 0, NULL, 0, NULL TSRMLS_CC) == SUCCESS) {
                                if (retval) {
index c07696aabe6a89c4ff43c290fc5d2e2c3661ac6c..286fb1e5a1c5e246b514ad5d8d91dbdf8d735449 100644 (file)
@@ -671,7 +671,8 @@ static void php_var_serialize_intern(smart_str *buf, zval **struc, HashTable *va
                                zval fname;
                                int res;
 
-                               if(Z_OBJCE_PP(struc) != PHP_IC_ENTRY) {
+                               if (Z_OBJCE_PP(struc) != PHP_IC_ENTRY &&
+                                   zend_hash_exists(&Z_OBJCE_PP(struc)->function_table, "__sleep", sizeof("__sleep"))) {
                                        INIT_PZVAL(&fname);
                                        ZVAL_STRINGL(&fname, "__sleep", sizeof("__sleep") - 1, 0);
                                        res = call_user_function_ex(CG(function_table), struc, &fname, 
index f01fe2adc879f66503aa71c65fad4d4a51e726bc..0db64025a3e685662b9c53d34a837ac56c26e82d 100644 (file)
@@ -298,7 +298,8 @@ static inline int object_common2(UNSERIALIZE_PARAMETER, long elements)
                return 0;
        }
 
-       if(Z_OBJCE_PP(rval) != PHP_IC_ENTRY) {
+       if (Z_OBJCE_PP(rval) != PHP_IC_ENTRY &&
+           zend_hash_exists(&Z_OBJCE_PP(rval)->function_table, "__wakeup", sizeof("__wakeup"))) {
                INIT_PZVAL(&fname);
                ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1, 0);
                call_user_function_ex(CG(function_table), rval, &fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC);
index 821b50b97c276def3ca4672b25cd3f1c0c15eb5c..94bbacccc7d78f01876f7ace54fbf095197acafb 100644 (file)
@@ -301,7 +301,8 @@ static inline int object_common2(UNSERIALIZE_PARAMETER, long elements)
                return 0;
        }
 
-       if(Z_OBJCE_PP(rval) != PHP_IC_ENTRY) {
+       if (Z_OBJCE_PP(rval) != PHP_IC_ENTRY &&
+           zend_hash_exists(&Z_OBJCE_PP(rval)->function_table, "__wakeup", sizeof("__wakeup"))) {
                INIT_PZVAL(&fname);
                ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1, 0);
                call_user_function_ex(CG(function_table), rval, &fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC);