Bug #79996 [NEW]: Reference trouble in closure

From: Date: Wed, 19 Aug 2020 12:30:46 +0000
Subject: Bug #79996 [NEW]: Reference trouble in closure
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228672@lists.php.net to get a copy of this message
From:             tropicano at ukr dot net
Operating system: Windows 10
PHP version:      7.4.9
Package:          *General Issues
Bug Type:         Bug
Bug description:Reference trouble in closure

Description:
------------
Not correct result in closure function.
Please review and fix it.

Test script:
---------------
$x = 0;

function main($func, $func2)
{
    return $func($func2);
}

function callback_main($func3)
{
    $data = 1;
    $func3($data);
    return $data;
}

echo main('callback_main', function (&$data) use ($x)
                           {
                               $data =& $x;
                               $data = 2;
                           }
          );

Expected result:
----------------
echo is: 1


Actual result:
--------------
must be: 2

-- 
Edit bug report at https://bugs.php.net/bug.php?id=79996&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=79996&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=79996&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=79996&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=79996&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=79996&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=79996&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=79996&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=79996&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=79996&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=79996&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79996&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=79996&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=79996&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=79996&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=79996&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=79996&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=79996&r=mysqlcfg


Thread (5 messages)

« previous php.bugs (#228672) next »