Skip to content

PHP 8 Named Arguments Not Supported #3243

Description

@zm-rylee

Describe the bug

The method AwsClientTrait::__call always looks for $args[0] but when using named arguments, they will exist as $args['args'] instead.

For example:

$client->createBucket(args: ["Bucket" => "some-bucket-name"]);

This will throw an exception with message:

Aws\\S3\\S3Client::isDirectoryBucket(): Argument #1 ($bucket) must be of type string, null given, called in \/var\/www\/html\/vendor\/aws\/aws-sdk-php\/src\/S3\/S3Client.php on line 734

As a workaround, I've used this snippet in projects that have strict ruling around named arguments:

use Aws\S3\S3Client as OriginalClient;

class S3Client extends OriginalClient {
    public function __call($name, array $args) {
        return parent::__call($name, [$args["args"]]);
    }
}

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

Full named arguments support matching the generation documentation and types.

Current Behavior

Exception thrown when using named arguments:

Aws\\S3\\S3Client::isDirectoryBucket(): Argument #1 ($bucket) must be of type string, null given, called in \/var\/www\/html\/vendor\/aws\/aws-sdk-php\/src\/S3\/S3Client.php on line 734

Reproduction Steps

Attempt to run any method that ends up hitting AwsClientTrait::__call method

Possible Solution

Changing:

# in AwsClientTrait::__call
$params = isset($args[0]) ? $args[0] : [];

To:

# in AwsClientTrait::__call
$params = $args['args'] ?? $args[0] ?? [];

Additional Information/Context

No response

SDK version used

3.369.25

Environment details (Version of PHP (php -v)? OS name and version, etc.)

PHP 8.4.15 - Debian GNU/Linux 13 (trixie) - Running in docker from php:8.4-fpm image

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.p3This is a minor priority issuequeuedThis issues is on the AWS team's backlog

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions