]> granicus.if.org Git - php/commitdiff
Make array write stuff work again correct and fix tests
authorMarcus Boerger <helly@php.net>
Wed, 16 Jul 2003 10:41:43 +0000 (10:41 +0000)
committerMarcus Boerger <helly@php.net>
Wed, 16 Jul 2003 10:41:43 +0000 (10:41 +0000)
ext/spl/spl_array.c
ext/spl/tests/array_access_001.phpt
ext/spl/tests/array_access_002.phpt

index 87a081a9e612310a0271d992c28940e231f12086..c21ed61461e7a86a04e49c11fe62d0f4a5ceacfd 100755 (executable)
@@ -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)++;
index 12b70e4c312647b7828a70db96373f2f9e1aeba4..4aea3d90f44a731e41b50381c7278b0018cd6edd 100755 (executable)
@@ -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)
index 64dccb3acb5b3dc8178b33829db46913a2febdba..e6616ea658e4093b786aa689bd4818ff15089113 100755 (executable)
@@ -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