summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2007-10-03 08:02:19 +0000
committerDmitry Stogov <dmitry@php.net>2007-10-03 08:02:19 +0000
commitc7047381f5ca559f617d95eaa708e01d133cb276 (patch)
tree53b84d69a4a8dcd2238558e9643778fc6a301e5b /Zend
parentf422acca269e1ee5a8cb0048f39862bc6ac50948 (diff)
downloadphp-git-c7047381f5ca559f617d95eaa708e01d133cb276.tar.gz
Fixed bug #42772 (Storing $this in a static var fails while handling a cast to string)
Diffstat (limited to 'Zend')
-rwxr-xr-xZend/tests/bug42772.phpt18
-rw-r--r--Zend/zend_vm_def.h19
-rw-r--r--Zend/zend_vm_execute.h76
3 files changed, 88 insertions, 25 deletions
diff --git a/Zend/tests/bug42772.phpt b/Zend/tests/bug42772.phpt
new file mode 100755
index 0000000000..8887bdbd7e
--- /dev/null
+++ b/Zend/tests/bug42772.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Bug #42772 (Storing $this in a static var fails while handling a cast to string)
+--FILE--
+<?php
+class Foo {
+ static public $foo;
+ function __toString() {
+ self::$foo = $this;
+ return 'foo';
+ }
+}
+
+$foo = (string)new Foo();
+var_dump(Foo::$foo);
+?>
+--EXPECT--
+object(Foo)#1 (0) {
+}
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 7b967e7c00..6405b09436 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -2727,9 +2727,11 @@ ZEND_VM_HANDLER(21, ZEND_CAST, CONST|TMP|VAR|CV, ANY)
zval *expr = GET_OP1_ZVAL_PTR(BP_VAR_R);
zval *result = &EX_T(opline->result.u.var).tmp_var;
- *result = *expr;
- if (!IS_OP1_TMP_FREE()) {
- zendi_zval_copy_ctor(*result);
+ if (opline->extended_value != IS_STRING) {
+ *result = *expr;
+ if (!IS_OP1_TMP_FREE()) {
+ zendi_zval_copy_ctor(*result);
+ }
}
switch (opline->extended_value) {
case IS_NULL:
@@ -2748,10 +2750,17 @@ ZEND_VM_HANDLER(21, ZEND_CAST, CONST|TMP|VAR|CV, ANY)
zval var_copy;
int use_copy;
- zend_make_printable_zval(result, &var_copy, &use_copy);
+ zend_make_printable_zval(expr, &var_copy, &use_copy);
if (use_copy) {
- zval_dtor(result);
*result = var_copy;
+ if (IS_OP1_TMP_FREE()) {
+ FREE_OP1();
+ }
+ } else {
+ *result = *expr;
+ if (!IS_OP1_TMP_FREE()) {
+ zendi_zval_copy_ctor(*result);
+ }
}
break;
}
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index ad01be669d..3ec65b0e3c 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -1895,9 +1895,11 @@ static int ZEND_CAST_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
zval *expr = &opline->op1.u.constant;
zval *result = &EX_T(opline->result.u.var).tmp_var;
- *result = *expr;
- if (!0) {
- zendi_zval_copy_ctor(*result);
+ if (opline->extended_value != IS_STRING) {
+ *result = *expr;
+ if (!0) {
+ zendi_zval_copy_ctor(*result);
+ }
}
switch (opline->extended_value) {
case IS_NULL:
@@ -1916,10 +1918,17 @@ static int ZEND_CAST_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
zval var_copy;
int use_copy;
- zend_make_printable_zval(result, &var_copy, &use_copy);
+ zend_make_printable_zval(expr, &var_copy, &use_copy);
if (use_copy) {
- zval_dtor(result);
*result = var_copy;
+ if (0) {
+
+ }
+ } else {
+ *result = *expr;
+ if (!0) {
+ zendi_zval_copy_ctor(*result);
+ }
}
break;
}
@@ -4461,9 +4470,11 @@ static int ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
zval *expr = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC);
zval *result = &EX_T(opline->result.u.var).tmp_var;
- *result = *expr;
- if (!1) {
- zendi_zval_copy_ctor(*result);
+ if (opline->extended_value != IS_STRING) {
+ *result = *expr;
+ if (!1) {
+ zendi_zval_copy_ctor(*result);
+ }
}
switch (opline->extended_value) {
case IS_NULL:
@@ -4482,10 +4493,17 @@ static int ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
zval var_copy;
int use_copy;
- zend_make_printable_zval(result, &var_copy, &use_copy);
+ zend_make_printable_zval(expr, &var_copy, &use_copy);
if (use_copy) {
- zval_dtor(result);
*result = var_copy;
+ if (1) {
+ zval_dtor(free_op1.var);
+ }
+ } else {
+ *result = *expr;
+ if (!1) {
+ zendi_zval_copy_ctor(*result);
+ }
}
break;
}
@@ -7599,9 +7617,11 @@ static int ZEND_CAST_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
zval *expr = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC);
zval *result = &EX_T(opline->result.u.var).tmp_var;
- *result = *expr;
- if (!0) {
- zendi_zval_copy_ctor(*result);
+ if (opline->extended_value != IS_STRING) {
+ *result = *expr;
+ if (!0) {
+ zendi_zval_copy_ctor(*result);
+ }
}
switch (opline->extended_value) {
case IS_NULL:
@@ -7620,10 +7640,17 @@ static int ZEND_CAST_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
zval var_copy;
int use_copy;
- zend_make_printable_zval(result, &var_copy, &use_copy);
+ zend_make_printable_zval(expr, &var_copy, &use_copy);
if (use_copy) {
- zval_dtor(result);
*result = var_copy;
+ if (0) {
+ if (free_op1.var) {zval_ptr_dtor(&free_op1.var);};
+ }
+ } else {
+ *result = *expr;
+ if (!0) {
+ zendi_zval_copy_ctor(*result);
+ }
}
break;
}
@@ -19662,9 +19689,11 @@ static int ZEND_CAST_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
zval *expr = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC);
zval *result = &EX_T(opline->result.u.var).tmp_var;
- *result = *expr;
- if (!0) {
- zendi_zval_copy_ctor(*result);
+ if (opline->extended_value != IS_STRING) {
+ *result = *expr;
+ if (!0) {
+ zendi_zval_copy_ctor(*result);
+ }
}
switch (opline->extended_value) {
case IS_NULL:
@@ -19683,10 +19712,17 @@ static int ZEND_CAST_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
zval var_copy;
int use_copy;
- zend_make_printable_zval(result, &var_copy, &use_copy);
+ zend_make_printable_zval(expr, &var_copy, &use_copy);
if (use_copy) {
- zval_dtor(result);
*result = var_copy;
+ if (0) {
+
+ }
+ } else {
+ *result = *expr;
+ if (!0) {
+ zendi_zval_copy_ctor(*result);
+ }
}
break;
}