Helpful Information
 
 
Category: vBulletin 3 Articles
[Tip] Five Things That Might Cause a Syntax Error

Typing Mistakes
We've already mentioned it once, but let's say it again. Check your spelling.

Construct is not closed properly
Most people take care to close loops and conditions, but it's still easy to be caught out when there
are several combined. Look out for something like this:
for ($loop1 = 0; $loop1<10; $loop1++)
{
for ($loop2 = 2; $loop2<20;$loop2++)
{
for ($loop3 = 3; $loop2<30; $loop3++)
{
…Code here…
}
}
It's not always obvious if the loops are closed 10 pages of code later. However, indenting the code
will certainly help, as well as making it easier to understand afterwards. Try formatting your loops
this way:
for ($loop1 = 0; $loop1<10; $loop1++)
{
for ($loop2 = 2; $loop2<20;$loop2++)
{
for ($loop3 = 3; $loop2<30; $loop3++)
{
...Code here...
}
}
This time, it's obvious that we're missing a closing brace.
Missing a semi-colon from the end of a statement

The semi-colon is vital in PHP – leave it off at your peril!

[/b] Getting the name of a function wrong [/b]
It might only be a small misunderstanding, but trying to use some like htmlspecialchar()
instead of htmlspecialchars() will generate a fatal error along the lines of
Fatal error: Call to undefined function: htmlspecialchar().

Not closing a string properly
It seems obvious, but if you fail to add a closing set of quotation marks to your string such as:
echo "Hello world;
PHP will generate a parse error.
The one upside to all of this is that syntax errors are usually quite easy to spot. The parse errors in PHP will
also give the accompanying line number of where the error was generated. Typically this line will be just
before or after the error itself depending on how the erroneous code affects a function, set of braces, or such
like. Also once you do spot them, they are almost all very easy to correct – unlike the next type of error we
will look at.

Marco, Webmaxtor.com

*Moved to correct forum*

Also please put your code in php boxes just for easier reading :)

- miSt

Mist, there are only five lines of code and I'm lazy. It sends the new added BB code always to the end, you have to cut + paste ...

One of your tips is indenting. I don't know about you, but:

1. Indenting doesn't work without preformatted tags like code and php
2. It takes me five seconds to type [php] and [code].

2. It takes me four seconds to type [php] and [code]. :o)

Actually, I'm blind I think, I see no difference in either of your codes (in fact both would give a parse error as both are only closing two of the loops)....however...indenting and formatting I agree with, but it's much easier for me to read thusly without parse errors:

for ($loop1 = 0; $loop1<10; $loop1++){
for ($loop2 = 2; $loop2<20; $loop2++){
for ($loop3 = 3; $loop2<30; $loop3++){
…Code here…
}
}
}










privacy (GDPR)