Skip to content

added test to reproduce issue with array_multisort #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

dmecke
Copy link

@dmecke dmecke commented Mar 25, 2019

reproduces #104

@moufmouf
Copy link
Member

Excellent. Thanks a lot for the test!

@moufmouf
Copy link
Member

Ok, I've tried to correct this and it turns out it is actually impossible :(

I changed the signature of the Safe\array_multisort function to be:

function array_multisort(array &$array1, &$array1_sort_order = SORT_ASC, &$array1_sort_flags = SORT_REGULAR, ...$params): void

But now, when I run your unit test, I get this:

array_multisort($sort, SORT_ASC, $integersSafe);
// Error: Cannot pass parameter 2 by reference

This is because in "userland" PHP, you cannot pass a constant in an argument that expects a reference.

The 2nd argument of array_multisort function can be either an int, OR an array passed by reference and there is no way to reproduce that in userland.

Hence, we are screwed :(.

The only solution I see so far is to remove array_multisort altogether from Safe. Which means introducing a BC break... 😡

@dmecke
Copy link
Author

dmecke commented Mar 25, 2019

array_multisort has indeed a terrible signature. I don't have a solution neither, but maybe an alternative to removing it altogether would be to throw an exception when an array is passed in and keep the current implementation. That would be a bc break as well, but in fact it is broken now when passing an array, so a bc break with an exception is imho still better that a misbehaviour without notice.

@k00ni
Copy link

k00ni commented Dec 16, 2019

I just stumbled over this project and checked this pull request. Please correct me if am wrong, but why not left the type for parameter $array1_sort_order and instead check it inside the function?

Based on the documentation the second parameter is by value anyway:

array_multisort (
    array &$array1 
    [, mixed $array1_sort_order = SORT_ASC 
        [, mixed $array1_sort_flags = SORT_REGULAR 
            [, mixed $... ]]] 
) : bool

Source: https://www.php.net/manual/en/function.array-multisort.php

@Kharhamel
Copy link
Collaborator

array_multisort will be removed in version 1.0.0. #167

@Kharhamel Kharhamel closed this Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants