From: Dmitry Stogov Date: Wed, 4 May 2005 08:45:46 +0000 (+0000) Subject: Fixed bug #30162 (Catching exception in constructor couses lose of $this) X-Git-Tag: php-5.0.1b1~329 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=37d16df05ceefaa519ca673c36a5e8d8f28e6169;p=php Fixed bug #30162 (Catching exception in constructor couses lose of $this) --- diff --git a/Zend/tests/bug30161.phpt b/Zend/tests/bug30161.phpt index 038a151e0e..22f8fb59e8 100755 --- a/Zend/tests/bug30161.phpt +++ b/Zend/tests/bug30161.phpt @@ -20,7 +20,7 @@ class hariCow extends FIIFO { } public function __toString() { - return "Rusticus in asino sedet."; + return "ok\n"; } } @@ -31,3 +31,4 @@ $db = new hariCow; echo $db; ?> --EXPECT-- +ok diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index e4774a8ee0..8aca967119 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -1890,9 +1890,11 @@ ZEND_VM_HELPER(zend_do_fcall_common_helper, ANY, ANY) if (EG(exception) && EX(fbc) && EX(fbc)->common.fn_flags&ZEND_ACC_CTOR) { EG(This)->refcount--; if (EG(This)->refcount == 1) { - zend_object_store_ctor_failed(EG(This) TSRMLS_CC); + zend_object_store_ctor_failed(EG(This) TSRMLS_CC); + } + if (should_change_scope && EG(This) != current_this) { + zval_ptr_dtor(&EG(This)); } - zval_ptr_dtor(&EG(This)); } else if (should_change_scope) { zval_ptr_dtor(&EG(This)); } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 174f577000..cdbe7596b4 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -254,9 +254,11 @@ static int zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS) if (EG(exception) && EX(fbc) && EX(fbc)->common.fn_flags&ZEND_ACC_CTOR) { EG(This)->refcount--; if (EG(This)->refcount == 1) { - zend_object_store_ctor_failed(EG(This) TSRMLS_CC); + zend_object_store_ctor_failed(EG(This) TSRMLS_CC); + } + if (should_change_scope && EG(This) != current_this) { + zval_ptr_dtor(&EG(This)); } - zval_ptr_dtor(&EG(This)); } else if (should_change_scope) { zval_ptr_dtor(&EG(This)); } @@ -30823,9 +30825,11 @@ static int zend_do_fcall_common_helper(ZEND_OPCODE_HANDLER_ARGS) if (EG(exception) && EX(fbc) && EX(fbc)->common.fn_flags&ZEND_ACC_CTOR) { EG(This)->refcount--; if (EG(This)->refcount == 1) { - zend_object_store_ctor_failed(EG(This) TSRMLS_CC); + zend_object_store_ctor_failed(EG(This) TSRMLS_CC); + } + if (should_change_scope && EG(This) != current_this) { + zval_ptr_dtor(&EG(This)); } - zval_ptr_dtor(&EG(This)); } else if (should_change_scope) { zval_ptr_dtor(&EG(This)); }