From a540179fe6e30d91434d0f31da88cf154043dcb0 Mon Sep 17 00:00:00 2001 From: Mark Karpeles Date: Thu, 20 Nov 2008 14:34:35 +0000 Subject: [PATCH] - ext/wddx: classes providing __sleep() are stored without properties (fixed) --- ext/wddx/tests/002.phpt | 21 +++++++++ ext/wddx/tests/003.phpt | 63 +++++++++++++++++++++++++ ext/wddx/tests/004.phpt | 63 +++++++++++++++++++++++++ ext/wddx/tests/005.phpt | 74 ++++++++++++++++++++++++++++++ ext/wddx/tests/bug35410_64bit.phpt | 1 - ext/wddx/wddx.c | 12 +++-- 6 files changed, 228 insertions(+), 6 deletions(-) create mode 100644 ext/wddx/tests/002.phpt create mode 100644 ext/wddx/tests/003.phpt create mode 100644 ext/wddx/tests/004.phpt create mode 100644 ext/wddx/tests/005.phpt diff --git a/ext/wddx/tests/002.phpt b/ext/wddx/tests/002.phpt new file mode 100644 index 0000000000..692bfa85c6 --- /dev/null +++ b/ext/wddx/tests/002.phpt @@ -0,0 +1,21 @@ +--TEST-- +wddx packet construction using wddx ressource +--SKIPIF-- + +--INI-- +precision=14 +--FILE-- + +--EXPECT-- +
TEST comment
some string756
diff --git a/ext/wddx/tests/003.phpt b/ext/wddx/tests/003.phpt new file mode 100644 index 0000000000..da5a1c42dd --- /dev/null +++ b/ext/wddx/tests/003.phpt @@ -0,0 +1,63 @@ +--TEST-- +wddx deserialize from ressource +--SKIPIF-- + +--INI-- +precision=14 +--FILE-- + +--EXPECT-- +array(11) { + ["aNull"]=> + NULL + ["aString"]=> + string(8) "a string" + ["aNumber"]=> + float(-12.456) + ["aDateTime"]=> + int(897625932) + ["aDateTime2"]=> + int(329632332) + ["aDateTime3"]=> + int(2223088332) + ["aBoolean"]=> + bool(true) + ["anArray"]=> + array(2) { + [0]=> + int(10) + [1]=> + string(14) "second element" + } + ["aBinary"]=> + string(11) "binary data" + ["anObject"]=> + array(2) { + ["s"]=> + string(8) "a string" + ["n"]=> + float(-12.456) + } + ["aRecordset"]=> + array(2) { + ["NAME"]=> + array(2) { + [0]=> + string(8) "John Doe" + [1]=> + string(8) "Jane Doe" + } + ["AGE"]=> + array(2) { + [0]=> + int(34) + [1]=> + int(31) + } + } +} diff --git a/ext/wddx/tests/004.phpt b/ext/wddx/tests/004.phpt new file mode 100644 index 0000000000..ae5a6b4bd5 --- /dev/null +++ b/ext/wddx/tests/004.phpt @@ -0,0 +1,63 @@ +--TEST-- +wddx session serializer handler (serialize) +--SKIPIF-- + +--INI-- +precision=14 +session.serialize_handler=wddx +session.use_cookies=0 +session.cache_limiter= +session.save_handler=files +--FILE-- +yes = "done"; } + + public function __sleep() { return array('bar', 'yes'); } + } + + session_start(); + + $_SESSION['data'] = array( + 'test1' => true, + 'test2' => 'some string', + 'test3' => 654321, + 'test4' => array( + 'some string', + true, + null + ), + ); + + $_SESSION['class'] = new foo(); + $_SESSION['class']->method(); + + var_dump(session_encode()); + + session_destroy(); +?> +--EXPECT-- +string(550) "
some string654321some stringfoookdone" diff --git a/ext/wddx/tests/005.phpt b/ext/wddx/tests/005.phpt new file mode 100644 index 0000000000..99e7a9e31f --- /dev/null +++ b/ext/wddx/tests/005.phpt @@ -0,0 +1,74 @@ +--TEST-- +wddx session serializer handler (deserialize) +--SKIPIF-- + +--INI-- +precision=14 +session.serialize_handler=wddx +session.use_cookies=0 +session.cache_limiter= +session.save_handler=files +--FILE-- +yes = "done"; } + } + + session_start(); + + session_decode("
some string654321some stringfoookdone"); + + var_dump($_SESSION); + + session_destroy(); +?> +--EXPECT-- +array(2) { + ["data"]=> + array(4) { + ["test1"]=> + bool(true) + ["test2"]=> + string(11) "some string" + ["test3"]=> + int(654321) + ["test4"]=> + array(3) { + [0]=> + string(11) "some string" + [1]=> + bool(true) + [2]=> + NULL + } + } + ["class"]=> + object(foo)#1 (2) { + ["bar"]=> + string(2) "ok" + ["yes"]=> + string(4) "done" + } +} diff --git a/ext/wddx/tests/bug35410_64bit.phpt b/ext/wddx/tests/bug35410_64bit.phpt index feb8e73b0c..15377b175e 100755 --- a/ext/wddx/tests/bug35410_64bit.phpt +++ b/ext/wddx/tests/bug35410_64bit.phpt @@ -48,7 +48,6 @@ $wddx = << WDX; -var_dump($wddx); var_dump(wddx_deserialize($wddx)); ?> --EXPECT-- diff --git a/ext/wddx/wddx.c b/ext/wddx/wddx.c index 4b2dbb9391..3364a9a8b6 100644 --- a/ext/wddx/wddx.c +++ b/ext/wddx/wddx.c @@ -458,7 +458,7 @@ static void php_wddx_serialize_object(wddx_packet *packet, zval *obj) char *key; ulong idx; char tmp_buf[WDDX_BUF_LEN]; - HashTable *objhash; + HashTable *objhash, *sleephash; TSRMLS_FETCH(); MAKE_STD_ZVAL(fname); @@ -469,7 +469,7 @@ static void php_wddx_serialize_object(wddx_packet *packet, zval *obj) * array of property names to be serialized. */ if (call_user_function_ex(CG(function_table), &obj, fname, &retval, 0, 0, 1, NULL TSRMLS_CC) == SUCCESS) { - if (retval && (objhash = HASH_OF(retval))) { + if (retval && (sleephash = HASH_OF(retval))) { PHP_CLASS_ATTRIBUTES; PHP_SET_CLASS_ATTRIBUTES(obj); @@ -483,10 +483,12 @@ static void php_wddx_serialize_object(wddx_packet *packet, zval *obj) php_wddx_add_chunk_static(packet, WDDX_VAR_E); PHP_CLEANUP_CLASS_ATTRIBUTES(); + + objhash = HASH_OF(obj); - for (zend_hash_internal_pointer_reset(objhash); - zend_hash_get_current_data(objhash, (void **)&varname) == SUCCESS; - zend_hash_move_forward(objhash)) { + for (zend_hash_internal_pointer_reset(sleephash); + zend_hash_get_current_data(sleephash, (void **)&varname) == SUCCESS; + zend_hash_move_forward(sleephash)) { if (Z_TYPE_PP(varname) != IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "__sleep should return an array only containing the names of instance-variables to serialize."); continue; -- 2.40.0