Skip to content
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

ResultPager cannot unpack array with string keys #798

Closed
tiptone opened this issue Feb 19, 2024 · 6 comments · May be fixed by #800
Closed

ResultPager cannot unpack array with string keys #798

tiptone opened this issue Feb 19, 2024 · 6 comments · May be fixed by #800

Comments

@tiptone
Copy link

tiptone commented Feb 19, 2024

ResultPager functions as expected unless I try to pass an array of parameters to fetchAll(). Using PHP 7.4.33 and m4tthumphrey/php-gitlab-api version 11.13.0.

This works as-expected:

$pager = new ResultPager($client);

try {
    $projects = $pager->fetchAll($client->projects(), 'all');
} catch (Exception $e) {
    throw new \Exception($e->getMessage());
}

This throws an error copy/pasted below the code:

$pager = new ResultPager($client);

try {
    $projects = $pager->fetchAll(
        $client->projects(),
        'all',
        [
            'search_namespaces' => true,
            'search' => $type,
        ]
    );
} catch (Exception $e) {
    throw new \Exception($e->getMessage());
}

PHP Fatal error: Uncaught Error: Cannot unpack array with string keys in /path/to/app/vendor/m4tthumphrey/php-gitlab-api/src/ResultPager.php:93
Stack trace:
#0 /path/to/app/vendor/m4tthumphrey/php-gitlab-api/src/ResultPager.php(134): Gitlab\ResultPager->fetch(Object(Gitlab\Api\Projects), 'all', Array)

Line 93 in GitLab\ResultPager:

$result = self::bindPerPage($api, $this->perPage)->$method(...$parameters);

If my Googling is correct, unpacking an array with string keys was not allowed until PHP 8.1 but the current version (11.13.0) requires php: ^7.4.15 || ^8.0.2. Please correct me if I'm looking at this all wrong.

@inuitviking
Copy link

The works fine (for me at least) on PHP 8.3.

I believe this is the version number with the prefixed caret that allows me to use PHP 8.3. Basically means I can use anything from PHP 8.0.2 up until (but not including) a hypothetical PHP 9.0.

So, if your project supports it, you could use PHP 8.1 just fine.

@tiptone
Copy link
Author

tiptone commented Mar 6, 2024

That is correct, the issue is not with PHP >= 8.1 but instead with the fact that this package advertises itself as compatible with php: ^7.4.15 || ^8.0.2 and that is not accurate. The current release of this library (I didn't investigate previous release compatibility) is only compatible with PHP >= 8.1.

@inuitviking
Copy link

Agreed. @GrahamCampbell, I have fixed this in #800, if you agree to this change.

@GrahamCampbell
Copy link
Member

The code sample is incorrect.

        [
            'search_namespaces' => true,
            'search' => $type,
        ]

should be

        [
            [
                'search_namespaces' => true,
                'search' => $type,
            ]
        ]

@GrahamCampbell
Copy link
Member

The array needs to be the list of params. The first param is an array, but you are passing the first param, instead of a list of params.

@tiptone
Copy link
Author

tiptone commented Mar 27, 2024

While I don't find it intuitive, it works! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants