Skip to content

Pluck will error on null value #216

@mbonneau

Description

@mbonneau

Pluck uses isset to check for the existence of a key. isset will not return true if the associated value is null which causes pluck to error.

This should use array_key_exists instead. (property_exists for objects)

Example:

\Rx\Observable::of([null])
    ->pluck(0)
    ->subscribe(
        fn($x) => printf("Next: %s\n", json_encode($x)),
        fn(\Throwable $e) => printf("Error: %s\n", $e->getMessage()),
        fn() => printf("Completed.\n")
    );

Outputs:

Error: Unable to pluck "0"

The expected output would be:

Next: null
Completed.

Here is the object version which exhibits the same behavior:

\Rx\Observable::of((object)['foo' => null])
    ->pluck('foo')
    ->subscribe(
        fn($x) => printf("Next: %s\n", json_encode($x)),
        fn(\Throwable $e) => printf("Error: %s\n", $e->getMessage()),
        fn() => printf("Completed.\n")
    );

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