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:
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")
);
Pluck uses
issetto check for the existence of a key.issetwill not returntrueif the associated value is null which causespluckto error.This should use
array_key_existsinstead. (property_existsfor objects)Example:
Outputs:
The expected output would be:
Here is the object version which exhibits the same behavior: