WP-e-Commerce icon indicating copy to clipboard operation
WP-e-Commerce copied to clipboard

WPSC_Cart is not traversable

Open JustinSainton opened this issue 9 years ago • 4 comments

https://github.com/wp-e-commerce/WP-e-Commerce/commit/a9009d016523074141211eb83dfd75bef865f36a introduced a loop that iterates over WPSC_Cart, which is not techncially traversable.

I don't fully understand what the intent of the commit is here. As such, I'm not clear if we should be iterating over the public properties of the object, or implement Iterator - or something else. Would welcome thoughts here from @JeffPyeBrook

JustinSainton avatar Nov 08 '16 00:11 JustinSainton

From what I can tell, reviewing that commit, the iteration over the WPSC_Cart object was not introduced in that commit, but simply moved around. Digging in to find the genesis of that loop.

jtsternberg avatar Nov 08 '16 01:11 jtsternberg

Looks like https://github.com/wp-e-commerce/WP-e-Commerce/commit/92d57ac is likely the culprit, as it introduces looping the wpsc_cart object.

jtsternberg avatar Nov 08 '16 02:11 jtsternberg

@JeffPyeBrook Make sense? We can either implement an iterator, or loop over get_object_vars() - so long as that's the intent here

JustinSainton avatar Nov 08 '16 02:11 JustinSainton

@JustinSainton Trying to remember the genesis of that loop. I do recall that there were two WordPress defects that drove the need to do that somewhat wacky construction/deconstruction. One of these defects was a fatal recursion issue.

Not debating if it is a good idea or not, but in PHP you could for loop over object properties. Under the hood I believe PHP does the quivelant of a cast to an array and then does the loop. Not sure I remember why the for loop was used in place of get_object_vars, but I suspect there was a reason or I would have done it with get_object_vars. It's a function I know, and use often.

I also remember thinking that when the cart class was refactored that the logic here would be replaced by accessing the refactored cart class' serialization/deserialization interface.

JeffPyeBrook avatar Nov 08 '16 21:11 JeffPyeBrook