cvs: ZendEngine2 / zend.h zend_object_handlers.c /tests bug31683.phpt

From: Date: Wed, 02 Feb 2005 07:19:22 +0000
Subject: cvs: ZendEngine2 / zend.h zend_object_handlers.c /tests bug31683.phpt
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-3356@lists.php.net to get a copy of this message
dmitry Wed Feb 2 02:19:22 2005 EDT Modified files: /ZendEngine2 zend.h zend_object_handlers.c /ZendEngine2/tests bug31683.phpt Log: Fixed bugs #29767 and #31683 (__get and __set methods must not modify property name). http://cvs.php.net/diff.php/ZendEngine2/zend.h?r1=1.270&r2=1.271&ty=u Index: ZendEngine2/zend.h diff -u ZendEngine2/zend.h:1.270 ZendEngine2/zend.h:1.271 --- ZendEngine2/zend.h:1.270 Tue Jan 25 08:08:05 2005 +++ ZendEngine2/zend.h Wed Feb 2 02:19:22 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend.h,v 1.270 2005/01/25 13:08:05 sniper Exp $ */ +/* $Id: zend.h,v 1.271 2005/02/02 07:19:22 dmitry Exp $ */ #ifndef ZEND_H #define ZEND_H @@ -605,6 +605,20 @@ (*ppzv_dest)->refcount = refcount; \ } +#define SEPARATE_ARG_IF_REF(varptr) \ + if (PZVAL_IS_REF(varptr)) { \ + zval *original_var = varptr; \ + ALLOC_ZVAL(varptr); \ + varptr->value = original_var->value; \ + varptr->type = original_var->type; \ + varptr->is_ref = 0; \ + varptr->refcount = 1; \ + zval_copy_ctor(varptr); \ + } else { \ + varptr->refcount++; \ + } + + #define ZEND_MAX_RESERVED_RESOURCES 4 #include "zend_variables.h" http://cvs.php.net/diff.php/ZendEngine2/zend_object_handlers.c?r1=1.108&r2=1.109&ty=u Index: ZendEngine2/zend_object_handlers.c diff -u ZendEngine2/zend_object_handlers.c:1.108 ZendEngine2/zend_object_handlers.c:1.109 --- ZendEngine2/zend_object_handlers.c:1.108 Tue Jan 18 20:46:26 2005 +++ ZendEngine2/zend_object_handlers.c Wed Feb 2 02:19:22 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_object_handlers.c,v 1.108 2005/01/19 01:46:26 sniper Exp $ */ +/* $Id: zend_object_handlers.c,v 1.109 2005/02/02 07:19:22 dmitry Exp $ */ #include "zend.h" #include "zend_globals.h" @@ -66,8 +66,13 @@ it should return whether the call was successfull or not */ + + SEPARATE_ARG_IF_REF(member); + zend_call_method_with_1_params(&object, ce, &ce->__get, ZEND_GET_FUNC_NAME, &retval, member); + zval_ptr_dtor(&member); + if (retval) { retval->refcount--; } @@ -80,7 +85,8 @@ zval *retval = NULL; int ret; zend_class_entry *ce = Z_OBJCE_P(object); - + + SEPARATE_ARG_IF_REF(member); value->refcount++; /* __set handler is called with two arguments: @@ -91,6 +97,7 @@ */ zend_call_method_with_2_params(&object, ce, &ce->__set, ZEND_SET_FUNC_NAME, &retval, member, value); + zval_ptr_dtor(&member); zval_ptr_dtor(&value); if (retval && zend_is_true(retval)) { @@ -334,12 +341,14 @@ if (instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC)) { if(offset == NULL) { /* [] construct */ - zval offset_null; - INIT_ZVAL(offset_null); - offset = &offset_null; + ALLOC_INIT_ZVAL(offset); + } else { + SEPARATE_ARG_IF_REF(offset); } zend_call_method_with_1_params(&object, ce, NULL, "offsetget", &retval, offset); + zval_ptr_dtor(&offset); + if (!retval) { if (!EG(exception)) { zend_error(E_ERROR, "Undefined offset for object of type %s used as array", ce->name); @@ -361,14 +370,15 @@ static void zend_std_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) { zend_class_entry *ce = Z_OBJCE_P(object); - zval tmp; - + if (instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC)) { if (!offset) { - INIT_ZVAL(tmp); - offset = &tmp; + ALLOC_INIT_ZVAL(offset); + } else { + SEPARATE_ARG_IF_REF(offset); } zend_call_method_with_2_params(&object, ce, NULL, "offsetset", NULL, offset, value); + zval_ptr_dtor(&offset); } else { zend_error(E_ERROR, "Cannot use object of type %s as array", ce->name); } @@ -382,7 +392,9 @@ int result; if (instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC)) { + SEPARATE_ARG_IF_REF(offset); zend_call_method_with_1_params(&object, ce, NULL, "offsetexists", &retval, offset); + zval_ptr_dtor(&offset); result = i_zend_is_true(retval); zval_ptr_dtor(&retval); return result; @@ -467,7 +479,9 @@ zval *retval; if (instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC)) { + SEPARATE_ARG_IF_REF(offset); zend_call_method_with_1_params(&object, ce, NULL, "offsetunset", &retval, offset); + zval_ptr_dtor(&offset); zval_ptr_dtor(&retval); } else { zend_error(E_ERROR, "Cannot use object of type %s as array", ce->name); http://cvs.php.net/diff.php/ZendEngine2/tests/bug31683.phpt?r1=1.1&r2=1.2&ty=u Index: ZendEngine2/tests/bug31683.phpt diff -u /dev/null ZendEngine2/tests/bug31683.phpt:1.2 --- /dev/null Wed Feb 2 02:19:22 2005 +++ ZendEngine2/tests/bug31683.phpt Wed Feb 2 02:19:22 2005 @@ -0,0 +1,97 @@ +--TEST-- +Bug #31683 (changes to $name in __get($name) override future parameters) +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + +class Foo implements ArrayAccess { + + function __get($test) { + var_dump($test); + $test = 'bug'; + } + + function __set($test, $val) { + var_dump($test); + var_dump($val); + $test = 'bug'; + $val = 'bug'; + } + + function __call($test, $arg) { + var_dump($test); + $test = 'bug'; + } + + function offsetget($test) { + var_dump($test); + $test = 'bug'; + return 123; + } + + function offsetset($test, $val) { + var_dump($test); + var_dump($val); + $test = 'bug'; + $val = 'bug'; + } + + function offsetexists($test) { + var_dump($test); + $test = 'bug'; + } + + function offsetunset($test) { + var_dump($test); + $test = 'bug'; + } + +} + +$foo = new Foo(); +$a = "ok"; + +for ($i=0; $i < 2; $i++) { + $foo->ok("ok"); + $foo->ok; + $foo->ok = "ok"; + $x = $foo["ok"]; + $foo["ok"] = "ok"; + isset($foo["ok"]); + unset($foo["ok"]); +// $foo[]; + $foo[] = "ok"; +// isset($foo[]); +// unset($foo[]); + $foo->$a; + echo "---\n"; +} +?> +--EXPECT-- +string(2) "ok" +string(2) "ok" +string(2) "ok" +string(2) "ok" +string(2) "ok" +string(2) "ok" +string(2) "ok" +string(2) "ok" +string(2) "ok" +NULL +string(2) "ok" +string(2) "ok" +--- +string(2) "ok" +string(2) "ok" +string(2) "ok" +string(2) "ok" +string(2) "ok" +string(2) "ok" +string(2) "ok" +string(2) "ok" +string(2) "ok" +NULL +string(2) "ok" +string(2) "ok" +---

« previous php.zend-engine.cvs (#3356) next »