]> granicus.if.org Git - php/commitdiff
Fix bug #45622 (isset($arrayObject->p) misbehaves with ArrayObject::ARRAY_AS_PROPS...
authorArnaud Le Blanc <lbarnaud@php.net>
Sat, 26 Jul 2008 12:33:34 +0000 (12:33 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Sat, 26 Jul 2008 12:33:34 +0000 (12:33 +0000)
ext/spl/spl_array.c
ext/spl/tests/bug45622.phpt [new file with mode: 0644]

index 2721f4f026f2be52b1bac23049b2db1d1aeb5a6e..64b7fff2800c8dc6e6544338a9b4468eba3c7ef4 100755 (executable)
@@ -700,13 +700,12 @@ static int spl_array_has_property(zval *object, zval *member, int has_set_exists
 {
        spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC);
 
-       if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0) {
-               if (!std_object_handlers.has_property(object, member, 2 TSRMLS_CC)) {
-                       return spl_array_has_dimension(object, member, has_set_exists TSRMLS_CC);
-               }
-               return 0; /* if prop doesn't exist at all mode 0/1 cannot return 1 */
+       if (std_object_handlers.has_property(object, member, has_set_exists TSRMLS_CC)) {
+               return 1;
+       } else if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0) {
+               return spl_array_has_dimension(object, member, has_set_exists TSRMLS_CC);
        }
-       return std_object_handlers.has_property(object, member, has_set_exists TSRMLS_CC);
+       return 0;
 } /* }}} */
 
 static void spl_array_unset_property(zval *object, zval *member TSRMLS_DC) /* {{{ */
diff --git a/ext/spl/tests/bug45622.phpt b/ext/spl/tests/bug45622.phpt
new file mode 100644 (file)
index 0000000..c47b62c
--- /dev/null
@@ -0,0 +1,51 @@
+--TEST--
+SPL: Bug #45622 (isset($arrayObject->p) misbehaves with ArrayObject::ARRAY_AS_PROPS set
+--FILE--
+<?php
+
+class C extends ArrayObject {
+       public $p = 'object property';
+}      
+
+$ao = new C(array('p'=>'array element'));
+$ao->setFlags(ArrayObject::ARRAY_AS_PROPS);
+
+echo "\n--> Access the real property:\n";
+var_dump(isset($ao->p));
+var_dump($ao->p);
+
+echo "\n--> Remove the real property and access the array element:\n";
+unset($ao->p);
+var_dump(isset($ao->p));
+var_dump($ao->p);
+
+echo "\n--> Remove the array element and try access again:\n";
+unset($ao->p);
+var_dump(isset($ao->p));
+var_dump($ao->p);
+
+echo "\n--> Re-add the real property:\n";
+$ao->p = 'object property';
+var_dump(isset($ao->p));
+var_dump($ao->p);
+?>
+--EXPECTF--
+
+--> Access the real property:
+bool(true)
+%unicode|string%(15) "object property"
+
+--> Remove the real property and access the array element:
+bool(true)
+%unicode|string%(13) "array element"
+
+--> Remove the array element and try access again:
+bool(false)
+
+Notice: Undefined index:  p in %s on line %d
+NULL
+
+--> Re-add the real property:
+bool(true)
+%unicode|string%(15) "object property"
+