Index: ext/standard/var.c =================================================================== RCS file: /repository/php-src/ext/standard/var.c,v retrieving revision 1.203.2.7.2.18.2.4 diff -u -r1.203.2.7.2.18.2.4 var.c --- ext/standard/var.c 2 Nov 2007 19:40:39 -0000 1.203.2.7.2.18.2.4 +++ ext/standard/var.c 6 Nov 2007 19:44:51 -0000 @@ -726,19 +726,21 @@ ZVAL_STRINGL(&fname, "__sleep", sizeof("__sleep") - 1, 0); res = call_user_function_ex(CG(function_table), &struc, &fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC); - 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 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); + zval_ptr_dtor(&retval_ptr); + return; } - return; } }