Index: ext/standard/var.c =================================================================== RCS file: /repository/php-src/ext/standard/var.c,v retrieving revision 1.271 diff -u -r1.271 var.c --- ext/standard/var.c 2 Nov 2007 09:43:04 -0000 1.271 +++ ext/standard/var.c 6 Nov 2007 19:22:24 -0000 @@ -1003,19 +1003,24 @@ ZVAL_ASCII_STRINGL(&fname, "__sleep", sizeof("__sleep") - 1, 1); res = call_user_function_ex(CG(function_table), &struc, &fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC); zval_dtor(&fname); - if (res == SUCCESS && !EG(exception)) { - if (retval_ptr) { - if (HASH_OF(retval_ptr)) { - php_var_serialize_class(buf, struc, retval_ptr, var_hash TSRMLS_CC); - } else { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "__sleep should return an array only containing the names of instance-variables to serialize"); - /* we should still add element even if it's not OK, - * since we already wrote the length of the array before */ - smart_str_appendl(buf,"N;", 2); - } + + if (res == SUCCESS && !EG(exception) && retval_ptr) { + /* only serialize using the return value + if it's an array, allow NULLs to fall through */ + if (HASH_OF(retval_ptr)) { + php_var_serialize_class(buf, struc, retval_ptr, var_hash TSRMLS_CC); + zval_ptr_dtor(&retval_ptr); + return; + } else if (Z_TYPE_P(retval_ptr) != IS_NULL) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "__sleep should return an array " + "containing the names of instance-variables to " + "serialize, or NULL."); + /* we should still add element even if it's not OK, + since we already wrote the length of the array before */ + smart_str_appendl(buf,"N;", 2); zval_ptr_dtor(&retval_ptr); + return; } - return; } }