Magento1.8 – How to Know if Mage::getModel(‘customer/customer’)->load() Succeeded?

customerdatabasemagento-1.8model

I want to know what if a customer ID I was trying to load was invalid. When I do this:

$customer = Mage::getModel('customer/customer')->load(12345);

If this customer exists, I get the data.

The problem is, if the customer ID doesn't exist, I still get something:

array (size=2)
  'created_at' => string '2016-05-24T15:59:18+00:00' (length=25)
  'group_id' => string '1' (length=1)

I needed a way where I can sort of say,

if(!$customer) {....

or

if(count($customer) < 1) { ....

But since there is always something in the returned array, how can I really know if a customer exists in the database?

Best Answer

Most of the time, the right test is to check whether the loaded object has an ID.

if ($customer->getId()) {
    // This is an existing customer
} else {
    // This is not an existing customer
}