PHP Debugging

0

PHP DebuggingOk, so quite a lot of newbies to PHP commonly get syntax errors. I’m just going to post a few commonly known errors, failed remedies and the proper resorts to these errors.

Error 1: “Unexpected $ at line x (normally end line of your PHP file)”

Don’t do this: Go through your PHP file and remove every single $ you see.
I recommend: You check that you have added enough }’s to equalise the {‘s.

For example:

$bar) {
if

($bar<$foo) {
echo “$bar is bigger than $foo”;
}
?>

is wrong, as you have more {‘s than }’s. To make your code work, you must have equal {}’s.

Error 2: “Unexpected } at line x (normally end of your PHP file)”

Don’t do this: Add another { in a random place, or remove all of your }’s all together.
I recommend: Go to the bottom of your PHP code, and remove one } and then reupload. If you still have the error, remove another. If this doesn’t work then check you’ve added a semicolon at the end of the last line, e.g. this is wrong:

while($foo = $bar) {
if($bar =

$dog) {
echo “$bar is equal to $dog”
}
}
}
?>

Error 3: “Unexpected T_ECHO (or T_anything for that matter)”

Don’t do this: Remove all your echos or just remove anything..
I recommend: Check your syntax carefully, it’s normally a semicolon issue on the previous line. If this isn’t the case, then you might be missing a bracket, i.e.

if

(($blah=”something”)||($blah=”somethingelse”) echo “Blah”; ?>

More to be added soon. I hope this helps, kind of.

Show Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>