...

View Full Version : why config.php file doesn't has "?>" tag in vbulletin ??



crazy.works
10-31-2009, 02:28 PM
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

kbluhm
10-31-2009, 02:46 PM
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.

CFMaBiSmAd
10-31-2009, 02:46 PM
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.

kbluhm
10-31-2009, 02:52 PM
Edit: Depending on if you are an optimist or a pessimist -

Good point. :thumbsup:

oesxyl
10-31-2009, 04:23 PM
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

kbluhm
10-31-2009, 05:24 PM
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.

crazy.works
10-31-2009, 06:02 PM
thanks guys :)

Fou-Lu
11-01-2009, 03:04 AM
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
$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
$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
$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).

kbluhm
11-01-2009, 03:59 PM
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
$a = 0;
printf("\$a = %d\n", $a);
++$a;

Valid:


<?php
$a = 0;

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

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

<?php

printf("\$a = %d\n", $a);

Valid:


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


Hello, <?php echo $user->name; ?>!

Fou-Lu
11-01-2009, 07:52 PM
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 /.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum