how to use var_dump and print_r in magento

Posted by Damodar Bashyal on April 24, 2009

 

This one is crazy with magento because sometimes it works and sometimes it just shows blank page. Once it gave me a real hard time. Finally found solution somewhere.

//I just had to do was add 
->debug()

//on the object that i wanted to print as:
$obj->debug();

//e.g. if i had
$_cart = Mage::getModel('checkout/cart');

//to use print_r or var_dump, i needed to do
print_r($_cart->debug());

These are methods available for a product:

Array
(
[0] => getResourceCollection
[1] => getUrlModel
[2] => validate
[3] => getName
[4] => getPrice
[5] => getTypeId
[6] => getStatus
[7] => getTypeInstance
[8] => setTypeInstance
[9] => getLinkInstance
[10] => getIdBySku
[11] => getCategoryId
[12] => getCategory
[13] => setCategoryIds
[14] => getCategoryIds
[15] => getCategoryCollection
[16] => getWebsiteIds
[17] => getStoreIds
[18] => getAttributes
[19] => canAffectOptions
[20] => cleanCache
[21] => getPriceModel
[22] => getTierPrice
[23] => getTierPriceCount
[24] => getFormatedTierPrice
[25] => getFormatedPrice
[26] => getFinalPrice
[27] => getCalculatedFinalPrice
[28] => getMinimalPrice
[29] => getSpecialPrice
[30] => getSpecialFromDate
[31] => getSpecialToDate
[32] => getRelatedProducts
[33] => getRelatedProductIds
[34] => getRelatedProductCollection
[35] => getRelatedLinkCollection
[36] => getUpSellProducts
[37] => getUpSellProductIds
[38] => getUpSellProductCollection
[39] => getUpSellLinkCollection
[40] => getCrossSellProducts
[41] => getCrossSellProductIds
[42] => getCrossSellProductCollection
[43] => getCrossSellLinkCollection
[44] => getGroupedLinkCollection
[45] => getMediaAttributes
[46] => getMediaGalleryImages
[47] => addImageToMediaGallery
[48] => getMediaConfig
[49] => duplicate
[50] => isSuperGroup
[51] => isSuperConfig
[52] => isGrouped
[53] => isConfigurable
[54] => isSuper
[55] => getVisibleInCatalogStatuses
[56] => isVisibleInCatalog
[57] => getVisibleInSiteVisibilities
[58] => isVisibleInSiteVisibility
[59] => isSalable
[60] => isVirtual
[61] => isSaleable
[62] => isInStock
[63] => getAttributeText
[64] => getCustomDesignDate
[65] => getProductUrl
[66] => formatUrlKey
[67] => getUrlPath
[68] => addAttributeUpdate
[69] => toArray
[70] => fromArray
[71] => loadParentProductIds
[72] => delete
[73] => getRequestPath
[74] => getGiftMessageAvailable
[75] => getRatingSummary
[76] => isComposite
[77] => getSku
[78] => getWeight
[79] => getOptionInstance
[80] => getProductOptionsCollection
[81] => addOption
[82] => getOptionById
[83] => getOptions
[84] => getIsVirtual
[85] => addCustomOption
[86] => setCustomOptions
[87] => getCustomOptions
[88] => getCustomOption
[89] => hasCustomOptions
[90] => canBeShowInCategory
[91] => getAvailableInCategories
[92] => getDefaultAttributeSetId
[93] => getImageUrl
[94] => getSmallImageUrl
[95] => getThumbnailUrl
[96] => getReservedAttributes
[97] => isReservedAttribute
[98] => setOrigData
[99] => loadByAttribute
[100] => getStore
[101] => getWebsiteStoreIds
[102] => setAttributeDefaultValue
[103] => getAttributeDefaultValue
[104] => getIdFieldName
[105] => getId
[106] => setId
[107] => getResourceName
[108] => getCollection
[109] => load
[110] => afterLoad
[111] => save
[112] => getResource
[113] => getEntityId
[114] => __construct
[115] => isDeleted
[116] => setIdFieldName
[117] => addData
[118] => setData
[119] => unsetData
[120] => getData
[121] => _getData
[122] => setDataUsingMethod
[123] => getDataUsingMethod
[124] => getDataSetDefault
[125] => hasData
[126] => __toArray
[127] => _prepareArray
[128] => __toXml
[129] => toXml
[130] => __toJson
[131] => toJson
[132] => __toString
[133] => toString
[134] => __call
[135] => __get
[136] => __set
[137] => isEmpty
[138] => _underscore
[139] => _camelize
[140] => serialize
[141] => getOrigData
[142] => dataHasChangedFor
[143] => isDirty
[144] => flagDirty
[145] => debug
[146] => offsetSet
[147] => offsetExists
[148] => offsetUnset
[149] => offsetGet
[150] => offsetUnset
[151] => offsetSet
[152] => offsetGet
[153] => offsetExists
)

For firePHP check:http://activecodeline.com/utilize-firebug-and-firephp-to-speed-up-magento-development/

Kat posted on - Thursday 5th of November 2009 05:05:29 PM

Thanks, most useful!!!!!

Theo posted on - Thursday 27th of June 2013 10:37:17 PM

Very good tip!

tarun posted on - Monday 5th of January 2015 09:03:31 AM

hard to find your blog and save my time!!@@@#$## very nice tutorial for debug....
 
not published on website


QR Code: how to use var_dump and print_r in magento