Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jul 2008
    Posts
    150
    Thanks
    24
    Thanked 0 Times in 0 Posts

    why config.php file doesn't has "?>" tag in vbulletin ??

    well, the last week was my first time to get in touch with the vbulletin, so after the installation i decided to make little modifications in the config directory, the config calling and the stuff like that to secure the forum that i have built. But i couldn't understand why and how the config.php file doesn't has "?>" tag at the end of it ????!!!
    so please anybody can explain to me how and why the config.php file doesn't has "?>" tag at the end of it ????!!!
    Beside anybody can provide any nice links or tutorials about explanation for how the vbulletin system works please ?

    thanks a lot
    Okay...

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    It's not necessary, and it guarantees no extraneous whitespace.

    I make it a point in development to never end a file with ?>

    This eliminates the possibility of accidental line breaks or whitespace following the tag, should a header be sent at any point.

  • Users who have thanked kbluhm for this post:

    crazy.works (10-31-2009)

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    Edit: Depending on if you are an optimist or a pessimist -

    The ?> tag is optional when it would be the last thing before the end of a file. Either the programmer was being lazy or he was compensating for not being able to find white-space after the ?> tag he did have in that file, which would have become content that is output to the browser if that file is included into another file.

    Since this is non-standard and inconstant usage of matching opening and closing tags, it should be avoided. It is always best to write code that is correct then to try to work around problems in case the work around becomes invalid in some future version. Correct code will always be correct. Code with a work around solution in it often breaks again.
    Last edited by CFMaBiSmAd; 10-31-2009 at 02:50 PM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    crazy.works (10-31-2009)

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    Edit: Depending on if you are an optimist or a pessimist -
    Good point.

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    Edit: Depending on if you are an optimist or a pessimist -
    Pessimist: Can't be worst then that.
    Optimist: Yes, it can.

    I think that depends of context,

    best regards

  • #6
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    To be honest, I don't think of this at all as bad practice.

    Plus, we are human, and thus mistakes such as as line breaks following the closing PHP tag are always a possibility. I have even used editors that under default settings will append an EOL.

    I'm not saying it is impossible to catch spaces or EOLs at the end of a file. On the contrary, it is without a question possible. What I'm saying is that it is even better practice (in my opinion) to eliminate any possibility of having to check and not even leave that door open as something I have to worry about.

  • Users who have thanked kbluhm for this post:

    crazy.works (10-31-2009)

  • #7
    Regular Coder
    Join Date
    Jul 2008
    Posts
    150
    Thanks
    24
    Thanked 0 Times in 0 Posts
    thanks guys
    Okay...

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by kbluhm View Post
    To be honest, I don't think of this at all as bad practice.

    Plus, we are human, and thus mistakes such as as line breaks following the closing PHP tag are always a possibility. I have even used editors that under default settings will append an EOL.

    I'm not saying it is impossible to catch spaces or EOLs at the end of a file. On the contrary, it is without a question possible. What I'm saying is that it is even better practice (in my opinion) to eliminate any possibility of having to check and not even leave that door open as something I have to worry about.
    I'm afraid I need to disagree.
    Final execution instruction semi-colons are also not required in php. The ?> implies a semi-colon. It is of course not compatible with the omitted ?> tag.
    This is valid:
    PHP Code:
    <?php
    $a 
    0;
    printf("\$a = %d\n"$a);
    ++
    $a // This is fine
    ?>
    Now, lets create something you'll see often (this example is of course pitiful, but it should demonstrate what I am meaning):
    PHP Code:
    <?php
    $a 
    0;

    printf("\$a = %d\n"$a);
    ++
    $a
    ?>

    <!-- LOTS AND LOTS OF HTML Stuff. -->

    <?php

    printf
    ("\$a = %d\n"$a);
    ?>
    So far so good. Lets say that the embedded html is removed and replaced with a template call for which we now merge together our PHP code blocks. I'll just print it out here:
    PHP Code:
    <?php
    $a 
    0;

    printf("\$a = %d\n"$a);
    ++
    $a
    print ('<!-- LOTS AND LOTS OF HTML Stuff. -->');

    printf("\$a = %d\n"$a);
    ?>
    And.... syntax error. Nothing is incorrect in either block, but combining multiple php blocks and making use of lesser known 'features' that caused this problem. Granted, experienced developers can debug this without any problems, but newer developers will be confused by why the original worked but the new did not (I assumed that the html replacement is fine as well of course).

    Also, I should mention that PHP is supposed to remove trailing linefeed's immediately after the ?> tag. It will not remove linefeeds preceeded by a space however. I believe this is also only a single linefeed, not multiple. [Note: I just tested this, it only does a single line feed. Uncertain if we're looking at just a standard \n or if we're also covering \r\n]

    And don't get me wrong kbluhm, I'm not saying that this practice is wrong. I'm saying that I wouldn't recommend it for new php developers in order to prevent problems like the one above (specific to the semi-colon omitting). Just because it can be omitted doesn't mean that its a good idea (at least some of the time).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #9
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    You may have missed my point. I am not advising the omission of *any and all* final-execution syntax, just the closing PHP tag when it would otherwise appear at the very end of a file.

    The semicolon alone will not allow you to jump from PHP code to client output... but the ?> tag will.

    Valid:
    PHP Code:
    <?php
    $a 
    0;
    printf("\$a = %d\n"$a);
    ++
    $a;
    Valid:
    PHP Code:
    <?php
    $a 
    0;

    printf("\$a = %d\n"$a);
    ++
    $a;
    ?>

    <!-- LOTS AND LOTS OF HTML Stuff. -->

    <?php

    printf
    ("\$a = %d\n"$a);
    Valid:
    PHP Code:
    <?php
    $a 
    0;

    printf("\$a = %d\n"$a);
    ++
    $a;
    print (
    '<!-- LOTS AND LOTS OF HTML Stuff. -->');

    printf("\$a = %d\n"$a);
    I do agree, for beginners, this should probably be taken in steps, but all I've suggested is that if the very end of the PHP file is ?>, then I would omit it. I never said anything about anything else, including semicolons. In fact, I would advise the use of semicolons even when they are unnecessary:
    PHP Code:
    Hello, <?php echo $user->name?>!
    Last edited by kbluhm; 11-01-2009 at 04:12 PM.

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I didn't miss the point, I'm merely comparing it to another possibility that can be omitted that will create problems. The same goes to omission of the ?> tags; consider how often that php is embedded within html code. If a developer is used to omitting the end tag, it will increase the probability that the omission will occur when the intention is to enter html.

    Omitting the ?> just doesn't feel... complete (just like the final semi-colon; it is well... bad practice to leave that off). Kinda like a single sided html tag without the /.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •