Number [god I don’t know] in the “Reasons Magento/PHP drives you Crazy” series.
Trying loading a product object that doesn’t exist.
$product = Mage::getModel('catalog/product')->loadByAttribute('sku','NO SUCH SKU');
var_dump($product);
You’ll find $product
contains NULL
. Now try loading an attribute object that doesn’t exist.
$attribute = Mage::getModel('catalog/resource_eav_attribute')
->loadByCode('catalog_product','NO SUCH ATTRIBUTE');
var_dump($attribute);
You’ll find that $attribute
contains an unpopulated attribute object.
If you’re a Java
/C#
programmer, this drives you crazy because the loadByAttribute
method should always return a product object (because methods have typed return values in those languages/system).
If you’re a PHP/Ruby/Python person you might expect to get NULL
back from a method like this, but you’d expect Magento to behave consistently across object types. It doesn’t matter what the system does (returns NULL
or returns an unpopulated object), it matters that the system behaves consistently when doing the same thing. (The same thing meaning instantiating an object)