|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-06-26 19:11 UTC] felipe@php.net
-Summary: array_splice problem with Closures
+Summary: converting closure to array yields empty array
[2010-06-26 19:14 UTC] felipe@php.net
[2010-06-26 19:18 UTC] felipe@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: felipe
[2010-06-26 19:18 UTC] felipe@php.net
[2010-06-26 19:18 UTC] felipe@php.net
-Package: Arrays related
+Package: Scripting Engine problem
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 09 04:00:01 2025 UTC |
Description: ------------ array_splice don't works with Closures. Test script: --------------- <?php $items = array( 'to remove' , 'item' ); var_dump( phpversion() ); array_splice( $items , 0 , 1 , 'works with strings' ); var_dump( $items ); array_splice( $items , 0 , 1 , 10 ); //with numbers var_dump( $items ); array_splice( $items , 0 , 1 , true ); //with booleans var_dump( $items ); array_splice( $items , 0 , 1 , array( 'it\'s' , 'ok' ) ); //with arrays var_dump( $items ); $items = array( 'to remove' , 'item' ); $func = function(){ return 'just a test'; }; array_splice( $items , 0 , 1 , $func ); //but not with Closures var_dump( $items ); Expected result: ---------------- string(5) "5.3.0" array(2) { [0]=> string(18) "works with strings" [1]=> string(4) "item" } array(2) { [0]=> int(10) [1]=> string(4) "item" } array(2) { [0]=> bool(true) [1]=> string(4) "item" } array(3) { [0]=> string(4) "it's" [1]=> string(2) "ok" [2]=> string(4) "item" } array(2) { [0]=> object(Closure)#2 (0) { } [1]=> string(4) "item" } Actual result: -------------- PHP 5.3.0: string(5) "5.3.0" array(2) { [0]=> string(18) "works with strings" [1]=> string(4) "item" } array(2) { [0]=> int(10) [1]=> string(4) "item" } array(2) { [0]=> bool(true) [1]=> string(4) "item" } array(3) { [0]=> string(4) "it's" [1]=> string(2) "ok" [2]=> string(4) "item" } array(1) { [0]=> string(4) "item" } -------------------------------------------- PHP 5.3.2 string(5) "5.3.2" array(2) { [0]=> string(18) "works with strings" [1]=> string(4) "item" } array(2) { [0]=> int(10) [1]=> string(4) "item" } array(2) { [0]=> bool(true) [1]=> string(4) "item" } array(3) { [0]=> string(4) "it's" [1]=> string(2) "ok" [2]=> string(4) "item" } array(1) { [0]=> string(4) "item" } -------------------------------------------- PHP 5.3.3-dev string(9) "5.3.3-dev" array(2) { [0]=> string(18) "works with strings" [1]=> string(4) "item" } array(2) { [0]=> int(10) [1]=> string(4) "item" } array(2) { [0]=> bool(true) [1]=> string(4) "item" } array(3) { [0]=> string(4) "it's" [1]=> string(2) "ok" [2]=> string(4) "item" } array(1) { [0]=> string(4) "item" }