I am trying to print an array in magento but it does not echo anything. In the file


at around line 87 there is a piece of code something like this

<?php foreach ($_rates as $_rate): ?>

When I try to output the contents of $_rates variable using

<?php echo "<pre>";print_r($_rates->getData());die;?>

I get an error stating Call to a member function getData() on array, I understood from this that $_rates variable is an array. So when I try to use print_r($_rates) to see the content of $_rates nothing is outputted on the screen, I just get a blank screen.

My question is if $_rates is an array then why I am not able to print it on the screen.

  • are you sure it is not empty? – Piyush May 31 '18 at 6:23
  • If it was empty then also array with two small brackets must have been shown on the screen. something like this : array( ) – Rajeev Singh May 31 '18 at 6:34

You need to try with below way,

<?php foreach ($_rates as $_rate): ?>
<?php echo "<pre>";print_r($_rate->getData());die;?>
<?php endforeach; ?>
  • it worked like this. But why I am not able to print $_rates on the screen if it is also an array. – Rajeev Singh May 31 '18 at 6:39
  • just try with var_dump($_rates); – Rakesh Jesadiya May 31 '18 at 8:33
  • Magento objects tend to be really big. There's a lot of tight coupling of code so almost every object outputs most all of the entire loaded codebase. That's why you use getData. That focuses on dumping the actual data in an object rather than its whole definition. – Rian May 31 '18 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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