KnpLabs / KnpLabs/knp-components
Using array_key_exists() on objects is deprecated when using paginate() with object target
- Dominant language
- PHP
- Stars
- 773
- Forks
- 139
- Avg merge
- 22h 3m
- Merged PRs (30d)
- 1
Description
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:
```diff
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?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in vendor/knplabs/knp-components/src/Knp/Component/Pager/Pagination/AbstractPagination.php at offsetExists() around line 163, then reproduce paginate() with an object target. Verify that checking the offset no longer emits the reported deprecation and that pagination still handles the object target correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100