When I try to use get cart items in a onepage checkout block, It always leads to Allowed Memory Exhausted error. The code I am using:


Even just accessing Mage::getSingleton('checkout/session') leads to the same problem. The exact problem has been mentioned here http://nickwan.wordpress.com/2011/10/16/magento-deadly-loop/ but I could not find a solution to it.

I am using Magento CE and have already tried with saving session data in file system/db.

PS: I believe this is some issue of circular reference. Suggest.

  • Well, how much memory does PHP have? May 1, 2014 at 22:23

2 Answers 2


Try to use


Instead of

  • The limit is not the issue. I've tried increasing it. Accessing the session should not take so much memory. The session is anyways accessed throughout the store and there is no issue in the normal running of the website. I'm writing a new checkout module and want to access the cart contents in my Block but I am facing this issue. While trying to debug I placed the above code directly in the existent phtml file and yet the same issue.
    – mosiac
    Jan 31, 2014 at 13:57
  • Can you please give me the error message? And the value of memory_limit? Jan 31, 2014 at 13:58
  • It does not make a difference - Read the blog (link in the question). It is some problem in the magento core code which causes it to go in a never ending loop whenever this code is executed.
    – mosiac
    Jan 31, 2014 at 15:39
  • I have read the blog. Error message there is 'Allowedmemory size of 33554432 bytes'. 33554432 bytes = 32M. The minimum memory limit for magento is 256M; That's why I asked you to give me error text. Jan 31, 2014 at 15:46
  • THe error message: PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 471603201 bytes)
    – mosiac
    Jan 31, 2014 at 17:17

A direct var_dump() does not work for Varien Objects. The return value of all the functions mentioned in the above question were either tried to dump or echo.

Doing this causes the memory issue. Use the item renderers such as Mage_Checkout_Block_Cart_Item_Renderer to render the itemHtml() and the issue will not occur.

The issue is resolved but one question still remains that Why is it not possible to var_dump the session variable or the cart items.

  • Found this out while trying to resolve the bug. I guess magento really demands hard work even for simple product rendering :\
    – mosiac
    Jan 31, 2014 at 18:39
  • feel free to accept the answer if it is valid for you May 20, 2014 at 18:47
  • @mosiac you can use one of Varien_Object::debug() or Varien_Object::getData() methods in var_dump calls to dump objects data without getting memory leaks. Feb 13, 2015 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.