]> granicus.if.org Git - php/commitdiff
MFB: Fixed bug #45622 (isset($arrayObject->p) misbehaves with
authorArnaud Le Blanc <lbarnaud@php.net>
Thu, 14 May 2009 16:44:54 +0000 (16:44 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Thu, 14 May 2009 16:44:54 +0000 (16:44 +0000)
ArrayObject::ARRAY_AS_PROPS set)

ext/spl/spl_array.c
ext/spl/tests/arrayObject___construct_basic4.phpt
ext/spl/tests/arrayObject___construct_basic5.phpt
ext/spl/tests/arrayObject_magicMethods6.phpt
ext/spl/tests/arrayObject_setFlags_basic1.phpt
ext/spl/tests/bug45622.phpt [new file with mode: 0644]

index 08f391b956f3387513ce1c096765c7b2a257b12a..b9c7867483ad8fa7fbe1aea3de6b48eb2cb81204 100755 (executable)
@@ -671,13 +671,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) /* {{{ */
index 5bc7732ff377adbffe6acf4cf1df4c3168f093a1..d53896dade1c63e85dadf2b8c3e3338c3a98cb6f 100644 (file)
@@ -1,7 +1,5 @@
 --TEST--
 SPL: ArrayObject::__construct basic usage with ArrayObject::ARRAY_AS_PROPS. 
---XFAIL--
-Will fail until the fix to bug 45622 is backported from PHP53 to PHP52.
 --FILE--
 <?php
 class C {
index 78af691ac95d36b6ad06c31c3022ece64445705b..4aff61c66589da09c1a9458a9428eb30db2dab24 100644 (file)
@@ -1,7 +1,5 @@
 --TEST--
 SPL: ArrayObject::__construct basic usage with ArrayObject::STD_PROP_LIST|ArrayObject::ARRAY_AS_PROPS.
---XFAIL--
-Will fail unless the PHP53 fix to bug 45622 is backported to PHP52
 --FILE--
 <?php
 class C {
index 3edf4671dbd3a02ec87fee107cc116184e0f0f7e..b274d34cc42f6c1641b4789ded49fc96c5dec046 100644 (file)
@@ -133,8 +133,11 @@ object(UsesMagic)#%d (5) {
 }
 
 --> isset existent, non-existent and dynamic:
+In UsesMagic::__isset(a)
 bool(true)
+In UsesMagic::__isset(nonexistent)
 bool(false)
+In UsesMagic::__isset(dynamic)
 bool(true)
   Original wrapped object:
 object(C)#%d (5) {
@@ -183,4 +186,4 @@ object(UsesMagic)#%d (3) {
   int(3)
   ["priv:private"]=>
   string(6) "secret"
-}
\ No newline at end of file
+}
index e3e97f3b53090d172798e69ccf21b9f963a55181..41f2afa95f3566b55bd84e2e6a07ded0f8df27a5 100644 (file)
@@ -1,7 +1,5 @@
 --TEST--
 SPL: ArrayObject::setFlags basic usage with ArrayObject::ARRAY_AS_PROPS. 
---XFAIL--
-Currently fails on php.net due to bug 45622.
 --FILE--
 <?php
 class C extends ArrayObject {
diff --git a/ext/spl/tests/bug45622.phpt b/ext/spl/tests/bug45622.phpt
new file mode 100644 (file)
index 0000000..89e2330
--- /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)
+string(15) "object property"
+
+--> Remove the real property and access the array element:
+bool(true)
+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)
+string(15) "object property"
+