]> granicus.if.org Git - php/commitdiff
Fixed bug #42772 (Storing $this in a static var fails while handling a cast to string)
authorDmitry Stogov <dmitry@php.net>
Wed, 3 Oct 2007 08:02:19 +0000 (08:02 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 3 Oct 2007 08:02:19 +0000 (08:02 +0000)
NEWS
Zend/tests/bug42772.phpt [new file with mode: 0755]
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

diff --git a/NEWS b/NEWS
index 95405001797062027faf1f2f43a3c10a6edafc83..f926254be25f38f93fdbf57ee57943ad0109b610 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,8 @@ PHP                                                                        NEWS
 
 - Fixed bug #42785 (json_encode() formats doubles according to locale rather  
   then following standard syntax). (Ilia)
+- Fixed bug #42772 (Storing $this in a static var fails while handling a cast
+  to string). (Dmitry)
 - Fixed bug #42767 (highlight_string() truncates trailing comment). (Ilia)
 - Fixed bug #42739 (mkdir() doesn't like a trailing slash when safe_mode is 
   enabled). (Ilia)
diff --git a/Zend/tests/bug42772.phpt b/Zend/tests/bug42772.phpt
new file mode 100755 (executable)
index 0000000..8887bdb
--- /dev/null
@@ -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) {
+}
index 7b967e7c00c1346115a30f7df3af931109deaaad..6405b094369ac3beaffbd31b480efd562c159791 100644 (file)
@@ -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;
                }
index ad01be669dc7002b45a9373834ab887b3f2692c5..3ec65b0e3cf5755efba848034cbed6295fe77049 100644 (file)
@@ -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;
                }