2

Probably out of bad habit and laziness, before php 7, if I was debugging and I wanted to know a value I would put in my code either

echo '<pre>';
print_r($myvalue);
echo '</pre>';

or

echo '<pre>';
var_dump($myvalue);
echo '</pre>';

if the value I was after was in a function, for example, a function call after a form has been submitted I would use the same but with a break

echo '<pre>';
print_r($myvalue);
echo '</pre>';
break;

or

echo '<pre>';
var_dump($myvalue);
echo '</pre>';
break;

Prior to php version 7, php would complain about the break but at least it would let me see the $myvalue. Now in php7 it just throws a fatal error.

So what is the correct way to debug?

2

I often just use die($variable);, which should work in your case - break is just for loops. NB I'm not saying this is the best way, and I'm interested to see if other users have better ways of debugging.

I'd also recommend you look at the J!Dump plugin for what you are after. This gives a lot more information when you dump something.

  • Doing a little research substituting break; with exit; works fine in php7. – James Wadsworth Dec 6 '16 at 20:08

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.