summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2010-06-26 17:14:33 +0000
committerFelipe Pena <felipe@php.net>2010-06-26 17:14:33 +0000
commit87c87daaf356e55b6ba062672429d80b566c4adf (patch)
treea3180fed7dfecea46484f7a26be9ad07c369aae7 /Zend
parent80926568f19901678754d37e3b4039ad2b1ffb48 (diff)
downloadphp-git-87c87daaf356e55b6ba062672429d80b566c4adf.tar.gz
- Fixed bug #52193 (converting closure to array yields empty array)
Diffstat (limited to 'Zend')
-rw-r--r--Zend/tests/bug52193.phpt78
-rw-r--r--Zend/zend_operators.c10
2 files changed, 87 insertions, 1 deletions
diff --git a/Zend/tests/bug52193.phpt b/Zend/tests/bug52193.phpt
new file mode 100644
index 0000000000..b4e4b3aab9
--- /dev/null
+++ b/Zend/tests/bug52193.phpt
@@ -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)
+}
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index 4d69c622f3..3a89c9c71f 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -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 *));