vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   [Tip] Five Things That Might Cause a Syntax Error (https://vborg.vbsupport.ru/showthread.php?t=54313)

gmarik 06-13-2003 09:00 PM

[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

Dean C 06-15-2003 08:13 AM

*Moved to correct forum*

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

- miSt

gmarik 06-15-2003 01:57 PM

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 ...

filburt1 06-15-2003 02:35 PM

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].

gmarik 06-16-2003 02:42 PM

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

Cloudrunner 06-16-2003 10:35 PM

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:

PHP Code:

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




All times are GMT. The time now is 12:07 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01659 seconds
  • Memory Usage 1,720KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete