ID: 25667 Updated by: [EMAIL PROTECTED] Reported By: zeug at delirium dot ch -Status: Open +Status: Bogus Bug Type: Documentation problem Operating System: * PHP Version: Irrelevant New Comment:
It is documented (http://php.net/language.basic-syntax) that <?php echo "abc"; ?> <?php echo "def"; ?> will print "abcdef" (without any space), as the closing newline after the ?> is ignored. If you put any HTML code between the two blocks, then it is not ignored. PHP does not mangle the contents of HTML blocks. Previous Comments: ------------------------------------------------------------------------ [2003-09-26 06:05:50] zeug at delirium dot ch Legalize it :-) After all, with <?php switch ($var): ?> <?php case 1: ?> there's also a newline finishing the switch-clause that's residing outside the PHP-block. It should be clear, that <?php switch ($var): ?> HTML blah blah <?php case 1: ?> is illegal. But I guess I grab the point: An empty line is considered an empty line of HTML rather than an empty line of PHP. So the parser strips whitespace AFTER a <?php ?> block, but doesn't ignore empty lines. This behaviour makes sense in most cases but maybe this switch-whitespace-case one. Never mind, it smells like tweaking the parser for no big issue, so adding a phrase to the docs will do I guess. Thanks for the fast replies, that's really cool! ------------------------------------------------------------------------ [2003-09-26 05:24:16] tony2001 at phpclub dot net as Wez already said, ---- <?php switch ($return) ?> <?php case 1: ?> ---- and ---- <?php switch ($return) case 1: ?> ---- are not the same things. first is equal to: <?php switch ($return): echo "\n"; case 1: ?> and this is invalid syntax. ------------------------------------------------------------------------ [2003-09-26 05:18:56] zeug at delirium dot ch Now, that's a matter of taste. I code 99% as classes in external files. So only very little PHP remains in the actual page file, mainly to arrange the HTML output. Picture this: <html> <?php // here go a couple of PHP code using external // classfiles that set a $return value ?> * SOME HTML CODE * <?php select ($return) ?> <?php case 1: ?> * A BUNCH OF HTML CODE * <?php break ?> <?php case 2: ?> * OTHER HTML CODE * <?php break ?> ... <? endswitch ?> * FINAL HTML CODE * </html> I currently omit the empty line between the switch and the first case, yet why is one Newline after the swtich okay, but two Newlines fail parsing? ------------------------------------------------------------------------ [2003-09-26 05:01:18] tony2001 at phpclub dot net just don't open/close php-tags on every line of your script. <? switch () { //as many empty lines as you want. case 1: break; } ?> ------------------------------------------------------------------------ [2003-09-26 04:52:07] zeug at delirium dot ch Wow, that was fast :-) Why shouldn't you be allowed to have whitespace between the opening switch and the first case clause when it's okay to have whitespace between case clauses and the final case/default clause and endswitch - unless of cause eliminating this exception means messing up the parser code? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/25667 -- Edit this bug report at http://bugs.php.net/?id=25667&edit=1
