Alleen started by digging into a PHP method which was just annoying. _find_shipment_by_object_id would, when it couldn't find the ID, return false, instead of the more expected null. Not terrible, but annoying. Worse, it didn't return the shipment eihter, just a key which could be used to fetch a shipment from an array.

Again, all that's just annoying.

It was when looking at the delete_shipment method that Alleen had the facepalm moment.

public function delete_shipment($object_id) { $key = $this->_find_shipment_by_object_id($object_id); if ($key !== FALSE) { $obj = $this->_shipments[$key]; unset($obj, $this->_shipments[$key]); } return $this; }

The PHP unset method takes a list of variables, including potentially array elements, and deletes them. For whatever reason, the person who wrote this code decided to fetch the value stored in the array, then delete the variable holding the value and the array index holding the value, when the goal was simply to delete the element from the array.

They just enjoyed deleting so much, that they needed to delete it twice.

Alleen also wonders about the return $this. It seems like the intent was to build a fluent, chainable API, but the code is never used that way. We're left with a simple mystery, but at least they couldn't return twice.

[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!