From: Marcus Boerger Date: Wed, 16 Jul 2003 10:41:43 +0000 (+0000) Subject: Make array write stuff work again correct and fix tests X-Git-Tag: BEFORE_ARG_INFO~220 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aa9bde9a34fd62a2a5a7d042979666149794f9f2;p=php Make array write stuff work again correct and fix tests --- diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 87a081a9e6..c21ed61461 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -218,9 +218,18 @@ ZEND_EXECUTE_HOOK_FUNCTION(ZEND_ASSIGN_DIM) FREE_OP(Ts, op2, EG(free_op2)); if (&EX(opline)->result) { - EX_T(EX(opline)->result.u.var).var.ptr = retval; - EX_T(EX(opline)->result.u.var).var.ptr_ptr = NULL;/*&EX_T(EX(opline)->result.u.var).var.ptr;*/ - SELECTIVE_PZVAL_LOCK(retval, &EX(opline)->result); + if (retval->refcount < 2) { + zend_error(E_WARNING, "Method %s::set() did not return a value, using input value", obj_ce->name); + EX_T(EX(opline)->result.u.var).var.ptr = value; + SELECTIVE_PZVAL_LOCK(value, &EX(opline)->result); + DELETE_RET_ZVAL(retval); + } else { + EX_T(EX(opline)->result.u.var).var.ptr = retval; + retval->refcount--; + } + EX_T(EX(opline)->result.u.var).var.ptr_ptr = NULL; + } else { + DELETE_RET_ZVAL(retval); } EX(opline)++; diff --git a/ext/spl/tests/array_access_001.phpt b/ext/spl/tests/array_access_001.phpt index 12b70e4c31..4aea3d90f4 100755 --- a/ext/spl/tests/array_access_001.phpt +++ b/ext/spl/tests/array_access_001.phpt @@ -82,32 +82,28 @@ c::get(4th) int(4) c::exists(5th) -Notice: Undefined index: 5th in %s on line %d +Notice: Undefined index: 5th in %sarray_access_001.php on line %d NULL c::exists(6) -Notice: Undefined index: 6 in %s on line %d +Notice: Undefined index: 6 in %sarray_access_001.php on line %d NULL WRITE 1 -c::exists(1) c::set(1,Changed 1) c::exists(1) c::get(1) string(9) "Changed 1" WRITE 2 -c::exists(4th) c::set(4th,Changed 4th) c::exists(4th) c::get(4th) string(11) "Changed 4th" WRITE 3 -c::exists(5th) c::set(5th,Added 5th) c::exists(5th) c::get(5th) string(9) "Added 5th" WRITE 4 -c::exists(6) c::set(6,Added 6) c::exists(6) c::get(6) @@ -118,7 +114,6 @@ string(3) "1st" c::exists(2) c::get(2) string(3) "3rd" -c::exists(6) c::set(6,changed 6) c::exists(6) c::get(6) diff --git a/ext/spl/tests/array_access_002.phpt b/ext/spl/tests/array_access_002.phpt index 64dccb3acb..e6616ea658 100755 --- a/ext/spl/tests/array_access_002.phpt +++ b/ext/spl/tests/array_access_002.phpt @@ -10,6 +10,7 @@ SPL: array_access without return in set() class c implements spl_array_access { public $a = array('1st', 1, 2=>'3rd', '4th'=>4); + function exists($index) { echo __METHOD__ . "($index)\n"; return array_key_exists($index, $this->a); @@ -82,41 +83,37 @@ c::get(4th) int(4) c::exists(5th) -Notice: Undefined index: 5th in %s on line %d +Notice: Undefined index: 5th in %sarray_access_002.php on line %d NULL c::exists(6) -Notice: Undefined index: 6 in %s on line %d +Notice: Undefined index: 6 in %sarray_access_002.php on line %d NULL WRITE 1 -c::exists(1) c::set(1,Changed 1) -Warning: Method c::set() did not return a value, using NULL in %s on line %d +Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d c::exists(1) c::get(1) string(9) "Changed 1" WRITE 2 -c::exists(4th) c::set(4th,Changed 4th) -Warning: Method c::set() did not return a value, using NULL in %s on line %d +Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d c::exists(4th) c::get(4th) string(11) "Changed 4th" WRITE 3 -c::exists(5th) c::set(5th,Added 5th) -Warning: Method c::set() did not return a value, using NULL in %s on line %d +Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d c::exists(5th) c::get(5th) string(9) "Added 5th" WRITE 4 -c::exists(6) c::set(6,Added 6) -Warning: Method c::set() did not return a value, using NULL in %s on line %d +Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d c::exists(6) c::get(6) string(7) "Added 6" @@ -126,12 +123,11 @@ string(3) "1st" c::exists(2) c::get(2) string(3) "3rd" -c::exists(6) c::set(6,changed 6) -Warning: Method c::set() did not return a value, using NULL in %s on line %d +Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d c::exists(6) c::get(6) string(9) "changed 6" -NULL +string(9) "changed 6" Done