krakjoe / uopz

User Operations for Zend
Other
356 stars 47 forks source link

uopz_set_hook closure receive extra arguments when function call through call_user_func and call_user_func_array #109

Closed noldor closed 5 years ago

noldor commented 5 years ago

Reproduction:

<?php

declare(strict_types=1);

class Test {
    public function some()
    {

    }
}

uopz_set_hook(Test::class, 'some', function (...$args) {
    var_dump($args);
});

call_user_func([new Test(), 'some'], 1, 2);
call_user_func_array([new Test(), 'some'], [1, 2]);
(new Test())->some(1, 2);

Output:

test.php:11:
array(3) {
  [0] =>
  array(2) {
    [0] =>
    class Test#2 (0) {
    }
    [1] =>
    string(4) "some"
  }
  [1] =>
  int(1)
  [2] =>
  int(2)
}
test.php:11:
array(2) {
  [0] =>
  array(2) {
    [0] =>
    class Test#2 (0) {
    }
    [1] =>
    string(4) "some"
  }
  [1] =>
  array(2) {
    [0] =>
    int(1)
    [1] =>
    int(2)
  }
}
test.php:11:
array(2) {
  [0] =>
  int(1)
  [1] =>
  int(2)
}

So, as you can see, hook closure receive expected arguments only when it called directly. Is this is the expected behavior?

Tested on php 7.3, 7.2, 7.1 uopz version: git master