php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78433 I found nowhere possibility to unpack reference expected variables to child fn
Submitted: 2019-08-21 09:47 UTC Modified: 2019-08-21 13:15 UTC
From: 6562680 at gmail dot com Assigned:
Status: Duplicate Package: Reflection related
PHP Version: 7.2.21 OS: Win10
Private report: No CVE-ID: None
 [2019-08-21 09:47 UTC] 6562680 at gmail dot com
Description:
------------
When i want to write facade for function that works by reference i should fully copy function signature into facade, otherwise when unpacking facade loses all references or something.

It means i cant decorate or make facade with arguments unpacking, because i'll lost all references on these bridge.

Test script:
---------------
// declare
function append(array &$ref)
{
  $ref[] = 1;
}

Class Lib
{
  public static function __callStatic($method, $arguments)
  {
    // just ignore $method for example...
    return append(...$arguments);

    // could be call_user_func('append', ...$arguments);
    // could be call_user_func_array('append', $arguments);
    // even could be call_user_func([ SomeOtherClass::class, 'append' ], ...$arguments);
  }
}

// run
$arr = [1];
append($arr);
var_dump($arr); // [1,1] // OK!
Lib::neverMind($arr);
var_dump($arr); // [1,1] // WTF? It should unpack args by references and then copy-on-write! Seems copy-on-write triggered on unpacking


Expected result:
----------------
Saving references when passing arguments to child function
Take care about magic __call, __callStatic and so on where we have 2nd parameter with arguments (possible packing)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-08-21 13:15 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2019-08-21 13:15 UTC] nikic@php.net
Duplicate of bug #71256.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 12:01:27 2024 UTC