]> granicus.if.org Git - php/commitdiff
- Fixed bug #52193 (converting closure to array yields empty array)
authorFelipe Pena <felipe@php.net>
Sat, 26 Jun 2010 17:14:33 +0000 (17:14 +0000)
committerFelipe Pena <felipe@php.net>
Sat, 26 Jun 2010 17:14:33 +0000 (17:14 +0000)
NEWS
Zend/tests/bug52193.phpt [new file with mode: 0644]
Zend/zend_operators.c

diff --git a/NEWS b/NEWS
index f08b39d1b4efa053fda2855b76d26cec92559402..3e69fec80ea821a1dfc118f519d8e84e75e00ec2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,10 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2010, PHP 5.3.3 RC2
 - Implemented FR #51295 (SQLite3::busyTimeout not existing). (Mark)
+
 - Fixed the mail.log ini setting when no filename was given. (Johannes)
+
+- Fixed bug #52193 (converting closure to array yields empty array). (Felipe)
 - Fixed bug #52183 (Reflectionfunction reports invalid number of arguments for
   function aliases). (Felipe)
 - Fixed bug #52162 (custom request header variables with numbers are removed). 
diff --git a/Zend/tests/bug52193.phpt b/Zend/tests/bug52193.phpt
new file mode 100644 (file)
index 0000000..b4e4b3a
--- /dev/null
@@ -0,0 +1,78 @@
+--TEST--
+Bug #52193 (converting closure to array yields empty array)
+--FILE--
+<?php
+
+var_dump((array) 1);
+var_dump((array) NULL);
+var_dump((array) new stdclass);
+var_dump($h = (array) function () { return 2; });
+var_dump($h[0]());
+
+$i = function () use (&$h) {
+       return $h;
+};
+
+var_dump($x = (array)$i);
+var_dump($y = $x[0]);
+var_dump($y());
+
+$items = range(1, 5);
+$func = function(){ return 'just a test'; };
+
+array_splice($items, 0 , 4, $func);
+var_dump($items);
+
+?>
+--EXPECTF--
+array(1) {
+  [0]=>
+  int(1)
+}
+array(0) {
+}
+array(0) {
+}
+array(1) {
+  [0]=>
+  object(Closure)#1 (0) {
+  }
+}
+int(2)
+array(1) {
+  [0]=>
+  object(Closure)#2 (1) {
+    ["static"]=>
+    array(1) {
+      ["h"]=>
+      &array(1) {
+        [0]=>
+        object(Closure)#1 (0) {
+        }
+      }
+    }
+  }
+}
+object(Closure)#2 (1) {
+  ["static"]=>
+  array(1) {
+    ["h"]=>
+    &array(1) {
+      [0]=>
+      object(Closure)#1 (0) {
+      }
+    }
+  }
+}
+array(1) {
+  [0]=>
+  object(Closure)#1 (0) {
+  }
+}
+array(2) {
+  [0]=>
+  object(Closure)#3 (0) {
+  }
+  [1]=>
+  int(5)
+}
index 7ce2e6283ad6d7e1219aaec56786d65488f018ff..24a2b1e417763769eb555cdc5d5ea4b5c6215ba0 100644 (file)
@@ -30,6 +30,7 @@
 #include "zend_multiply.h"
 #include "zend_strtod.h"
 #include "zend_exceptions.h"
+#include "zend_closures.h"
 
 #define LONG_SIGN_MASK (1L << (8*sizeof(long)-1))
 
@@ -646,7 +647,14 @@ ZEND_API void convert_to_array(zval *op) /* {{{ */
 
                                ALLOC_HASHTABLE(ht);
                                zend_hash_init(ht, 0, NULL, ZVAL_PTR_DTOR, 0);
-                               if (Z_OBJ_HT_P(op)->get_properties) {
+                               if (Z_OBJCE_P(op) == zend_ce_closure) {
+                                       convert_scalar_to_array(op, IS_ARRAY TSRMLS_CC);
+                                       if (Z_TYPE_P(op) == IS_ARRAY) {
+                                               zend_hash_destroy(ht);
+                                               FREE_HASHTABLE(ht);
+                                               return;
+                                       }
+                               } else if (Z_OBJ_HT_P(op)->get_properties) {
                                        HashTable *obj_ht = Z_OBJ_HT_P(op)->get_properties(op TSRMLS_CC);
                                        if (obj_ht) {
                                                zend_hash_copy(ht, obj_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));