php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67924 Closure and lambda problem
Submitted: 2014-08-28 13:05 UTC Modified: 2014-12-30 10:42 UTC
From: tin dot legall at wishgroupe dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.4.4 OS: Debian
Private report: No CVE-ID: None
 [2014-08-28 13:05 UTC] tin dot legall at wishgroupe dot com
Description:
------------
Take example #2 at the following address and switch $double and $number declarations

http://php.net/manual/en/language.types.callable.php

Expected result:
----------------
2 4 6 8 10

Actual result:
--------------
1 2 3 4 5

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-28 16:11 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2014-08-28 16:11 UTC] requinix@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

Not a description of what you did but the actual code. Because what it sounds like you're describing creates something totally incorrect and will spew warnings.
 [2014-08-28 17:43 UTC] tin dot legall at wishgroupe dot com
-Status: Feedback +Status: Open -PHP Version: 5.4.32 +PHP Version: 5.4.4
 [2014-08-28 17:43 UTC] tin dot legall at wishgroupe dot com
Here is the code example that illustrates the problem:

<?php

// This is our range of numbers
$numbers = range(1, 5);

// Our closure
$double = function($a) {
    return $a * 2;
};

// Use the closure as a callback here to 
// double the size of each element in our 
// range
$new_numbers = array_map($double, $numbers);

print implode(' ', $new_numbers);
?>

Expected result:
----------------
2 4 6 8 10

Actual result:
--------------
1 2 3 4 5
 [2014-08-28 18:51 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2014-08-28 18:51 UTC] requinix@php.net
Works for me. http://3v4l.org/pOTkX

You've tried that exact code? No modifications whatsoever?
Do you have any Zend extensions installed? If so you need to try without them as they can modify PHP's behavior.
 [2014-12-30 10:42 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC