php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80736 array_uintersect parameters difference
Submitted: 2021-02-12 09:53 UTC Modified: 2021-02-12 15:58 UTC
From: jurigag at gmail dot com Assigned:
Status: Open Package: Arrays related
PHP Version: 8.0.2 OS: Ubuntu 18.04
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jurigag at gmail dot com
New email:
PHP Version: OS:

 

 [2021-02-12 09:53 UTC] jurigag at gmail dot com
Description:
------------
When using PHP8 ReflectionFunction::getNumberOfParameters() for array_uintersect returns 2 and also they look like this:

array(2) {
  [0]=>
  object(ReflectionParameter)#2 (1) {
    ["name"]=>
    string(5) "array"
  }
  [1]=>
  object(ReflectionParameter)#3 (1) {
    ["name"]=>
    string(4) "rest"
  }
}

But for PHP7 it was looking like this:

array(3) {
  [0]=>
  object(ReflectionParameter)#2 (1) {
    ["name"]=>
    string(4) "arr1"
  }
  [1]=>
  object(ReflectionParameter)#3 (1) {
    ["name"]=>
    string(4) "arr2"
  }
  [2]=>
  object(ReflectionParameter)#4 (1) {
    ["name"]=>
    string(26) "callback_data_compare_func"
  }
}

Change itself isn't documented on docs, not sure why it was changed, but also when executing this function it works as it was previously.

Test script:
---------------
<?php

$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "GREEN", "B" => "brown", "yellow", "red");

print_r(array_uintersect($array1, $array2, "strcasecmp"));

$reflection = new ReflectionFunction('array_uintersect');
var_dump($reflection->getNumberOfParameters());
var_dump($reflection->getNumberOfRequiredParameters());
var_dump($reflection->getParameters());

Expected result:
----------------
Array
(
    [a] => green
    [b] => brown
    [0] => red
)
int(3)
int(3)
array(3) {
  [0]=>
  object(ReflectionParameter)#2 (1) {
    ["name"]=>
    string(4) "arr1"
  }
  [1]=>
  object(ReflectionParameter)#3 (1) {
    ["name"]=>
    string(4) "arr2"
  }
  [2]=>
  object(ReflectionParameter)#4 (1) {
    ["name"]=>
    string(26) "callback_data_compare_func"
  }
}

Actual result:
--------------
Array
(
    [a] => green
    [b] => brown
    [0] => red
)
int(2)
int(1)
array(2) {
  [0]=>
  object(ReflectionParameter)#2 (1) {
    ["name"]=>
    string(5) "array"
  }
  [1]=>
  object(ReflectionParameter)#3 (1) {
    ["name"]=>
    string(4) "rest"
  }
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-12 15:51 UTC] requinix@php.net
-Type: Bug +Type: Documentation Problem -Package: Reflection related +Package: Arrays related
 [2021-02-12 15:51 UTC] requinix@php.net
The documented signature is

array_uintersect ( array $array , array ...$arrays , callable $value_compare_func ) : array

but that isn't actually possible to do: a varargs parameter must be the last one in the list. Reflection is now returning to you the "actual" signature of the method, as one might implement manually in userland, where the first argument is an array and the rest is dynamic.

array_uintersect ( array $array , mixed ...$rest ) : array

This isn't just for array_uintersect but being applied across the board to most/all built-in functions.
 [2021-02-12 15:53 UTC] jurigag at gmail dot com
Yea, but this callable is missing in the parameters.
 [2021-02-12 15:58 UTC] requinix@php.net
It's missing because it's not part of the function signature. The callback is the last item in $rest, not a distinct parameter.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Nov 05 06:01:28 2024 UTC