knp-components
knp-components copied to clipboard
Fix PHP 7.4 deprecation, when using objects with paginate() on Paginator
Details see #294
Yes, will do
It seems like, the issue only happens with custom EventSubscribers. The existing ones are using slice, which is transforming the object into an array. This means the deprecation message will never show up. Should I create a dummy event for that test case, so the pagination returns an object instead of array? I know, this issue is related to a custom implementation, but it seems like doing it like this is not wrong, so I still thing this is a bug.
I think that we should ~change~ deprecate our current implementation and only accept array or ArrayIterator
Any other object does not make sense to be paginated.
By the way, isset
cannot replace array_key_exists
, because it's returning differently when a value is null
.
Sorry for my late response. Should I change my code to not use isset
or just close it, because it's supposed to work with arrays only anyway?
Sorry for my late response. Should I change my code to not use
isset
or just close it, because it's supposed to work with arrays only anyway?
Don't worry about the delay, there's no hurry. My suggestion is about restricting possible types for $items to two cases: array and ArrayIterator. Any other type should raise a deprecation for now, and an exception in the next major version. The phpdoc should be changed accordingly.
Any news on this?
Sorry, I was busy... I can have a look next week. I think it could be easy to solve by using typehints.
So before this condition (https://github.com/KnpLabs/knp-components/blob/master/src/Knp/Component/Pager/Paginator.php#L91) there should be a check, whether $itemsEvent->item
is an array or ArrayIterator
. For now it could be a deprecation message and later a strict check.
The best would be to check this inside ItemsEvent
(https://github.com/KnpLabs/knp-components/blob/master/src/Knp/Component/Pager/Event/ItemsEvent.php#L29), but since items
is a public property, this is not possible.
The latest version already restricts the type of $items to iterable
.
Again, if you can propose a failing test, it would be better.
I'm closing this since we don't support PHP 7.4 anymore