Get available methods for an object

There are no better shortcuts than a very good study but there’s a tip which can help you to get a bit of speed.

Have you ever tried to figure out what available methods you can use from a customer model in Magento?

Imagine you load the customer into a variable (or the product, order)

# load the customer
$customer = Mage::getModel('customer/customer')->load($params['id']);

but you’re not sure what methods/functions you can access, and here it comes the beauty:

# This will output an array with functions 
#  $customer variable should be The class name or an 
#  object instance (in our case - object instance)
print_r(
    get_class_methods($customer)
);

What exactly this function does (got from php.net):

Returns an array of method names defined for the class specified by class_name. In case of an error, it returns NULL.

And the output of the previous command would be something similar to this:

Array
(
    [0] => _construct
    [1] => getSharingConfig
    [2] => authenticate
    [3] => loadByEmail
    [4] => changePassword
    [5] => getName
    [6] => addAddress
    [7] => getAddressById
    [8] => getAddressItemById
    [9] => getAddressCollection
    [10] => getAddressesCollection
    [11] => getAddresses
    [12] => getAttributes
    [13] => getAttribute
    [14] => setPassword
    [15] => hashPassword
    [16] => generatePassword
    [17] => validatePassword
    [18] => encryptPassword
    [19] => decryptPassword
    [20] => getPrimaryAddress
    [21] => getPrimaryBillingAddress
    [22] => getDefaultBillingAddress
    [23] => getPrimaryShippingAddress
    [24] => getDefaultShippingAddress
    [25] => getPrimaryAddressIds
    [26] => getPrimaryAddresses
    [27] => getAdditionalAddresses
    [28] => isAddressPrimary
    [29] => sendNewAccountEmail
    [30] => isConfirmationRequired
    [31] => getRandomConfirmationKey
    [32] => sendPasswordReminderEmail
    [33] => sendChangedPasswordOrEmail
    [34] => sendPasswordResetConfirmationEmail
    [35] => getGroupId
    [36] => getTaxClassId
    [37] => isInStore
    [38] => getStore
    [39] => getSharedStoreIds
    [40] => getSharedWebsiteIds
    [41] => setStore
    [42] => validate
    [43] => validateResetPassword
    [44] => importFromTextArray
    [45] => unsetSubscription
    [46] => cleanAllAddresses
    [47] => addError
    [48] => getErrors
    [49] => resetErrors
    [50] => printError
    [51] => validateAddress
    [52] => getCreatedAtTimestamp
    [53] => reset
    [54] => isDeleteable
    [55] => setIsDeleteable
    [56] => isReadonly
    [57] => setIsReadonly
    [58] => canSkipConfirmation
    [59] => __clone
    [60] => getEntityType
    [61] => getEntityTypeId
    [62] => changeResetPasswordLinkToken
    [63] => isResetPasswordLinkTokenExpired
    [64] => cleanPasswordsValidationData
    [65] => getIdFieldName
    [66] => getId
    [67] => setId
    [68] => getResourceName
    [69] => getResourceCollection
    [70] => getCollection
    [71] => load
    [72] => afterLoad
    [73] => save
    [74] => afterCommitCallback
    [75] => isObjectNew
    [76] => getCacheTags
    [77] => getCacheIdTags
    [78] => cleanModelCache
    [79] => delete
    [80] => getResource
    [81] => getEntityId
    [82] => clearInstance
    [83] => __construct
    [84] => isDeleted
    [85] => hasDataChanges
    [86] => setIdFieldName
    [87] => addData
    [88] => setData
    [89] => unsetData
    [90] => unsetOldData
    [91] => getData
    [92] => setDataUsingMethod
    [93] => getDataUsingMethod
    [94] => getDataSetDefault
    [95] => hasData
    [96] => __toArray
    [97] => toArray
    [98] => toXml
    [99] => toJson
    [100] => toString
    [101] => __call
    [102] => __get
    [103] => __set
    [104] => isEmpty
    [105] => serialize
    [106] => getOrigData
    [107] => setOrigData
    [108] => dataHasChangedFor
    [109] => setDataChanges
    [110] => debug
    [111] => offsetSet
    [112] => offsetExists
    [113] => offsetUnset
    [114] => offsetGet
    [115] => isDirty
    [116] => flagDirty
)

As you can see as a result you get an array of method names defined for the class specified by class_name. In case of an error, it returns NULL.

But it should be noted that the returned methods are dependant on the current scope.