Skip to content

pluck does not pluck values if elements are of type ArrayAccess #38

@Tohnmeister

Description

@Tohnmeister

In PHP it's possible to implement a custom array class, by implementing the ArrayAccess interface. That way you can use any instance of your class as be it an array. We had our own implementation of pluck which could handle elements that did this. But underscore's pluck doesn't seem to be able to handle these custom array types.

The line from our own implementation that checked for keys existence in elements, was:

if (isset($element[$key])) { // Must use isset instead of array_key_exists, because the latter does not work correctly on self implementing ArrayAccess classes.

Note the comment.

It would be great if underscore would support this too. We'd rather use your pluck version than our own.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions