diff --git a/tests/serialize_001.phpt b/tests/serialize_001.phpt index af06467..baec2f0 100644 --- a/tests/serialize_001.phpt +++ b/tests/serialize_001.phpt @@ -20,6 +20,18 @@ catch(\V8JsException $e) { $stored = 'O:8:"V8Object":0:{}'; +try { + $obj2 = unserialize($stored); +} +catch(\V8JsException $e) { + var_dump(get_class($e)); + var_dump($e->getMessage()); +} + +var_dump(isset($obj2)); + +$stored = 'O:8:"V8Object":1:{s:3:"foo";i:23;}'; + try { $obj = unserialize($stored); } @@ -28,8 +40,7 @@ catch(\V8JsException $e) { var_dump($e->getMessage()); } -$v8->foo = $obj; - +var_dump(isset($obj3)); ?> ===EOF=== @@ -42,4 +53,8 @@ string(13) "V8JsException" string(54) "You cannot serialize or unserialize V8Object instances" string(13) "V8JsException" string(54) "You cannot serialize or unserialize V8Object instances" +bool(false) +string(13) "V8JsException" +string(54) "You cannot serialize or unserialize V8Object instances" +bool(false) ===EOF=== diff --git a/tests/serialize_basic.phpt b/tests/serialize_basic.phpt index bdd2520..0b14788 100644 --- a/tests/serialize_basic.phpt +++ b/tests/serialize_basic.phpt @@ -25,6 +25,16 @@ catch(\V8JsException $e) { var_dump($e->getMessage()); } +$stored = 'O:4:"V8Js":1:{s:3:"foo";i:23;}'; + +try { + $b = unserialize($stored); +} +catch(\V8JsException $e) { + var_dump(get_class($e)); + var_dump($e->getMessage()); +} + ?> ===EOF=== --EXPECT-- @@ -32,4 +42,6 @@ string(13) "V8JsException" string(50) "You cannot serialize or unserialize V8Js instances" string(13) "V8JsException" string(50) "You cannot serialize or unserialize V8Js instances" +string(13) "V8JsException" +string(50) "You cannot serialize or unserialize V8Js instances" ===EOF=== diff --git a/v8js.cc b/v8js.cc index f754a89..e86a50e 100644 --- a/v8js.cc +++ b/v8js.cc @@ -385,12 +385,16 @@ static HashTable *php_v8js_v8_get_properties(zval *object TSRMLS_DC) /* {{{ */ /* the garbage collector is running, don't create more zvals */ return NULL; } - if (obj->ctx == NULL) { - /* Half-constructed object. Shouldn't happen, but be safe. */ - return NULL; - } + ALLOC_HASHTABLE(obj->properties); zend_hash_init(obj->properties, 0, NULL, ZVAL_PTR_DTOR, 0); + + if (!obj->ctx) { + /* Half-constructed object, probably due to unserialize call. + * Just pass back properties hash so unserialize can write to + * it (instead of crashing the engine). */ + return obj->properties; + } } else { zend_hash_clean(obj->properties); }