CodeSOD: Unset-tled

by admin

Alleen began by digging right into a PHP technique which was simply annoying. _find_shipment_by_object_id would, when it couldn't discover the ID, return false, as a substitute of the extra anticipated null. Not horrible, however annoying. Worse, it didn't return the cargo eihter, only a key which could possibly be used to fetch a cargo from an array.

Once more, all that's simply annoying.

It was when wanting on the delete_shipment technique that Alleen had the facepalm second.

public operate 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 technique takes an inventory of variables, together with probably array components, and deletes them. For no matter cause, the one that wrote this code determined to fetch the worth saved within the array, then delete the variable holding the worth and the array index holding the worth, when the aim was merely to delete the factor from the array.

They only loved deleting a lot, that they wanted to delete it twice.

Alleen additionally wonders in regards to the return $this. It appears just like the intent was to construct a fluent, chainable API, however the code is rarely used that approach. We're left with a easy thriller, however not less than they couldn't return twice.


Utilize BuildMaster to launch your software program with confidence, on the tempo your small business calls for. Download in the present day!

Related Posts

Leave a Comment