]> granicus.if.org Git - php/commitdiff
fix #12793 - serialize will now spit a notice if the return value of __sleep is
authorThies C. Arntzen <thies@php.net>
Tue, 19 Mar 2002 11:25:21 +0000 (11:25 +0000)
committerThies C. Arntzen <thies@php.net>
Tue, 19 Mar 2002 11:25:21 +0000 (11:25 +0000)
bogus.

ext/standard/php_smart_str.h
ext/standard/var.c

index a1912141f4f3c25197ec1a2c4871f799bd3f51de..3bf94469ce80d908b8195b9aa874776c3287435f 100644 (file)
@@ -24,7 +24,7 @@
 #include <stdlib.h>
 #include <zend.h>
 
-#define smart_str_0(x) ((x)->c[(x)->len] = '\0')
+#define smart_str_0(x) do { if ((x)->c) { (x)->c[(x)->len] = '\0'; } } while (0);
 
 #ifndef SMART_STR_PREALLOC
 #define SMART_STR_PREALLOC 128
index 7eb7410243f57990df94e00850c7375c380d261e..82dc1181678c94e1e4ea9b7e3ac4c0fd54aae89d 100644 (file)
@@ -536,9 +536,15 @@ static void php_var_serialize_intern(smart_str *buf, zval **struc, HashTable *va
 
                                if (res == SUCCESS) {
                                        if (retval_ptr) {
-                                               if (HASH_OF(retval_ptr))
+                                               if (HASH_OF(retval_ptr)) {
                                                        php_var_serialize_class(buf, struc, retval_ptr, 
                                                                        var_hash TSRMLS_CC);
+                                               } else {
+                                                       php_error(E_NOTICE, "__sleep should return an array only "
+                                                                                               "containing the names of instance-variables to "
+                                                                                               "serialize.");
+                                               }
+
                                                zval_ptr_dtor(&retval_ptr);
                                        }
                                        return; 
@@ -623,7 +629,12 @@ PHP_FUNCTION(serialize)
        PHP_VAR_SERIALIZE_INIT(var_hash);
        php_var_serialize(&buf, struc, &var_hash TSRMLS_CC);
        PHP_VAR_SERIALIZE_DESTROY(var_hash);
-       RETVAL_STRINGL(buf.c, buf.len, 0);
+
+       if (buf.c) {
+               RETURN_STRINGL(buf.c, buf.len, 0);
+       } else {
+               RETURN_NULL();
+       }
 }
 
 /* }}} */