Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
[Tip] Five Things That Might Cause a Syntax Error
gmarik's Avatar
gmarik
Join Date: May 2002
Posts: 1,288

Nevermind

Mocsow
Show Printable Version Email this Page Subscription
gmarik gmarik is offline 06-13-2003, 10:00 PM

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
Reply With Quote
  #2  
Old 06-15-2003, 09:13 AM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

*Moved to correct forum*

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

- miSt
Reply With Quote
  #3  
Old 06-15-2003, 02:57 PM
gmarik's Avatar
gmarik gmarik is offline
 
Join Date: May 2002
Location: Mocsow
Posts: 1,288
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 ...
Reply With Quote
  #4  
Old 06-15-2003, 03:35 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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].
Reply With Quote
  #5  
Old 06-16-2003, 03:42 PM
gmarik's Avatar
gmarik gmarik is offline
 
Join Date: May 2002
Location: Mocsow
Posts: 1,288
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

2. It takes me four seconds to type [php] and [code]. )
Reply With Quote
  #6  
Old 06-16-2003, 11:35 PM
Cloudrunner's Avatar
Cloudrunner Cloudrunner is offline
 
Join Date: May 2003
Location: Butte, MT
Posts: 635
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
    }
  }

Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:42 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04268 seconds
  • Memory Usage 2,247KB
  • Queries Executed 21 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (5)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete