Skip to content

Using array_key_exists() on objects is deprecated when using paginate() with object target #294

@ThauEx

Description

@ThauEx

When using the paginate() method of the Paginator class with an object as target, it throws the following deprecation:

array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in vendor/knplabs/knp-components/src/Knp/Component/Pager/Pagination/AbstractPagination.php line 163

It can be fixed with the following change:

    public function offsetExists($offset): bool
    {
        if ($this->items instanceof \ArrayIterator) {
            return array_key_exists($offset, iterator_to_array($this->items));
        }

-        return array_key_exists($offset, $this->items);
+        return isset($this->items[$offset]);
    }

Since paginate has the following description for the $target argument:

  • @param mixed $target anything what needs to be paginated
    I would say this is a bug.

Should I open a PR for that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions