svn: /php/php-src/ branches/PHP_5_3/NEWS branches/PHP_5_3/Zend/tests/bug52193.phpt branches/PHP_5_3/Zend/zend_operators.c
trunk/Zend/tests/bug52193.phpt trunk/Zend/zend_operators.c
| From: | Felipe Pena | Date: | Sat, 26 Jun 2010 17:14:33 +0000 |
| Subject: | svn: /php/php-src/ branches/PHP_5_3/NEWS branches/PHP_5_3/Zend/tests/bug52193.phpt branches/PHP_5_3/Zend/zend_operators.c trunk/Zend/tests/bug52193.phpt trunk/Zend/zend_operators.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-62963@lists.php.net to get a copy of this message | ||
felipe Sat, 26 Jun 2010 17:14:33 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=300765
Log:
- Fixed bug #52193 (converting closure to array yields empty array)
Bug: http://bugs.php.net/52193 (Open) converting closure to
array yields empty array
Changed paths:
U php/php-src/branches/PHP_5_3/NEWS
A php/php-src/branches/PHP_5_3/Zend/tests/bug52193.phpt
U php/php-src/branches/PHP_5_3/Zend/zend_operators.c
A php/php-src/trunk/Zend/tests/bug52193.phpt
U php/php-src/trunk/Zend/zend_operators.c
Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS 2010-06-26 16:03:39 UTC (rev 300764)
+++ php/php-src/branches/PHP_5_3/NEWS 2010-06-26 17:14:33 UTC (rev 300765)
@@ -2,7 +2,10 @@
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 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).
Added: php/php-src/branches/PHP_5_3/Zend/tests/bug52193.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/Zend/tests/bug52193.phpt (rev 0)
+++ php/php-src/branches/PHP_5_3/Zend/tests/bug52193.phpt 2010-06-26 17:14:33 UTC (rev 300765)
@@ -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)
+}
Property changes on: php/php-src/branches/PHP_5_3/Zend/tests/bug52193.phpt
___________________________________________________________________
Added: svn:keywords
+ Id Rev Revision
Added: svn:eol-style
+ native
Modified: php/php-src/branches/PHP_5_3/Zend/zend_operators.c
===================================================================
--- php/php-src/branches/PHP_5_3/Zend/zend_operators.c 2010-06-26 16:03:39 UTC (rev 300764)
+++ php/php-src/branches/PHP_5_3/Zend/zend_operators.c 2010-06-26 17:14:33 UTC (rev 300765)
@@ -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 @@
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
*));
Added: php/php-src/trunk/Zend/tests/bug52193.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/bug52193.phpt (rev 0)
+++ php/php-src/trunk/Zend/tests/bug52193.phpt 2010-06-26 17:14:33 UTC (rev 300765)
@@ -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)
+}
Property changes on: php/php-src/trunk/Zend/tests/bug52193.phpt
___________________________________________________________________
Added: svn:keywords
+ Id Rev Revision
Added: svn:eol-style
+ native
Modified: php/php-src/trunk/Zend/zend_operators.c
===================================================================
--- php/php-src/trunk/Zend/zend_operators.c 2010-06-26 16:03:39 UTC (rev 300764)
+++ php/php-src/trunk/Zend/zend_operators.c 2010-06-26 17:14:33 UTC (rev 300765)
@@ -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 @@
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
*));