]> granicus.if.org Git - php/commitdiff
MFH: Better fix for #45622 (patch by robinf at php do net)
authorArnaud Le Blanc <lbarnaud@php.net>
Thu, 21 May 2009 13:26:29 +0000 (13:26 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Thu, 21 May 2009 13:26:29 +0000 (13:26 +0000)
ext/spl/spl_array.c
ext/spl/tests/arrayObject_magicMethods6.phpt
ext/spl/tests/bug45622b.phpt [new file with mode: 0644]

index b9c7867483ad8fa7fbe1aea3de6b48eb2cb81204..2c48923a3a1d457bfb16cf86f56836f5d59f64d2 100755 (executable)
@@ -671,12 +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 (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) {
+       if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0
+       && !std_object_handlers.has_property(object, member, 2 TSRMLS_CC)) {
                return spl_array_has_dimension(object, member, has_set_exists TSRMLS_CC);
        }
-       return 0;
+       return std_object_handlers.has_property(object, member, has_set_exists TSRMLS_CC);
+
 } /* }}} */
 
 static void spl_array_unset_property(zval *object, zval *member TSRMLS_DC) /* {{{ */
index b274d34cc42f6c1641b4789ded49fc96c5dec046..427b1d4f207f0dfab3d0febfb3d04cec03528cc8 100644 (file)
@@ -133,11 +133,8 @@ 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) {
diff --git a/ext/spl/tests/bug45622b.phpt b/ext/spl/tests/bug45622b.phpt
new file mode 100644 (file)
index 0000000..9d49392
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+Ensure fix to bug45622 doesn't cause __isset() to be called when ArrayObject::ARRAY_AS_PROPS is used.
+--FILE--
+<?php
+class UsesMagic extends ArrayObject {
+       function __get($n)     {  echo "In " . __METHOD__ . "!\n"; }
+       function __set($n, $v) {  echo "In " . __METHOD__ . "!\n"; }
+       function __isset($n)   {  echo "In " . __METHOD__ . "!\n"; }
+       function __unset($n)   {  echo "In " . __METHOD__ . "!\n"; }
+}
+$ao = new UsesMagic(array(), ArrayObject::ARRAY_AS_PROPS);
+
+echo "Doesn't trigger __get.\n";
+echo $ao->prop1;
+
+echo "Doesn't trigger __set.\n";    
+$ao->prop2 = 'foo';
+
+echo "Doesn't trigger __unset.\n";
+unset($ao->prop3);
+
+echo "Shouldn't trigger __isset.\n";
+isset($ao->prop4);
+?>
+--EXPECTF--
+Doesn't trigger __get.
+
+Notice: Undefined index:  prop1 in %s on line 11
+Doesn't trigger __set.
+Doesn't trigger __unset.
+
+Notice: Undefined index:  prop3 in %s on line 17
+Shouldn't trigger __isset.
\ No newline at end of file