summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2003-07-16 10:41:43 +0000
committerMarcus Boerger <helly@php.net>2003-07-16 10:41:43 +0000
commitaa9bde9a34fd62a2a5a7d042979666149794f9f2 (patch)
treee2ff316d6457476044ba8faaa4e4bb0ec7a5e943 /ext
parent15097151f4a7545c1d359bf86f495eb18b9842db (diff)
downloadphp-git-aa9bde9a34fd62a2a5a7d042979666149794f9f2.tar.gz
Make array write stuff work again correct and fix tests
Diffstat (limited to 'ext')
-rwxr-xr-xext/spl/spl_array.c15
-rwxr-xr-xext/spl/tests/array_access_001.phpt9
-rwxr-xr-xext/spl/tests/array_access_002.phpt22
3 files changed, 23 insertions, 23 deletions
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