php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52193 converting closure to array yields empty array
Submitted: 2010-06-26 17:11 UTC Modified: 2010-06-26 19:18 UTC
From: neto dot joaobatista at gmail dot com Assigned: felipe
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.3RC1 OS: Linux, Fedora 13 64 bits
Private report: No CVE-ID:
 [2010-06-26 17:11 UTC] neto dot joaobatista at gmail dot com
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"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [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
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=300765
Log: - Fixed bug #52193 (converting closure to array yields empty array)
 [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
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2010-06-26 19:18 UTC] felipe@php.net
-Package: Arrays related +Package: Scripting Engine problem
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 09:02:23 2014 UTC