Skip to content

Crash when an empty Traversable is entered into randomElements() #604

@KentarouTakeda

Description

@KentarouTakeda

Summary

Crash when an empty Traversable is entered into randomElements()

Versions

Version
PHP 8.2.3
fakerphp/faker 1.21.0

Self-enclosed code snippet for reproduction

# replace this with a self-enclosed usage example
BaseProvider::randomElements(new \ArrayIterator(), 0);

Expected output

# replace this with the expected output of your self-enclosed example

// Empty array should be returned.

Actual output

# replace this with the actual output of your self-enclosed example
TypeError: array_keys(): Argument #1 ($array) must be of type array, ArrayIterator given

Faker/src/Faker/Provider/Base.php:202

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions