Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

ItemList::removeItem can remove multiple Items at once #1038

Closed
benjaminpick opened this issue Jan 10, 2018 · 1 comment
Closed

ItemList::removeItem can remove multiple Items at once #1038

benjaminpick opened this issue Jan 10, 2018 · 1 comment

Comments

@benjaminpick
Copy link

benjaminpick commented Jan 10, 2018

In writing #1034, I discovered another potential bug:

Imagine adding an item twice:

$item = (new Item)->setName('blue car');
$itemList->addItem( $item );
$itemList->addItem( (new Item)->setName('blue car') );
$itemList->removeItem($item);

How many Items are now in the $itemList? Yes, none at all. This is because array_diff does not compare by reference, but by JSON representation of the internal state.

Is this on purpose?
(The same issue exists with many other PaypalModels.)

@bluk
Copy link
Contributor

bluk commented Jan 10, 2018

This is known behavior in this convenience method. It should be rare that you have the same items or other objects with the same exact JSON representation in real world scenarios. If you must control the exact items, you can use the setItems or equivalent setter for the property.

@bluk bluk closed this as completed Jan 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants