Re: #25667 [Com]: Strange switch-case behaviour (KMM6079774V20332L0KM)
| From: | abuse@swbell.net | Date: | Thu, 02 Oct 2003 18:47:29 +0000 |
| Subject: | Re: #25667 [Com]: Strange switch-case behaviour (KMM6079774V20332L0KM) | ||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969356493@lists.php.net to get a copy of this message | ||
Hello-
Thank you for contacting the SBC Internet Services Policy department.
The use of SBC Internet accounts to attempt to gain unauthorized access
to a host, server or network is prohibited by our Acceptable Use Policy
which may be found at the following URL:
http://sbc.yahoo.com/terms/
I will investigate your complaint and take appropriate action.
On behalf of SBC Internet, I apologize for any inconvenience caused by
our customer. Please do not hesitate to write again if you have any
questions or if you wish to report other instances of abuse by SBC
Internet customers.
Thank you,
The SBCIS Policy department
Original Message Follows:
-------------------------
ID: 25667
Comment by: tony2001 at phpclub dot net
Reported By: zeug at delirium dot ch
Status: Open
Bug Type: Documentation problem
Operating System: *
PHP Version: Irrelevant
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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?
------------------------------------------------------------------------
[2003-09-26 04:45:09] sniper@php.net
Actually this is not bug. You can't have anything between
switch()..case.. ever. It's not valid.
This is same as what you tried:
<?php
$var = 1;
switch (1) {
echo " ";
case 1:
echo $var;
}
?>
------------------------------------------------------------------------
[2003-09-26 04:34:08] zeug at delirium dot ch
Description:
------------
Hi there
This is a very minor bug concerning the structure of a source code
rather than its functionality. It's been dealt with in Bug #13387, yet
the case was closed back then when it seems to have been fixed in
4.2.0-dev. It's back in 4.3.3.
Here are some examples:
Example 1, okay:
<?php switch ($var): ?>
<?php case 1: ?>
<?php dothis() ?>
<?php endswitch ?>
Example 2, okay:
<?php switch ($var) { ?>
<?php case 1: ?>
<?php dothis() ?>
<?php } ?>
Example 3, syntax error:
<?php switch ($var): ?>
<?php case 1: ?>
<?php dothis() ?>
<?php endswitch ?>
The parser doesn't seem to like whitespace in HTML between switch and
case.
When mixing PHP and HTML code, the syntax in example 3 can improve
readablility.
Reproduce code:
---------------
<?php $var = 1 ?>
<?php switch ($var): ?>
<?php case 1: ?>
<?php print $var ?>
<?php endswitch ?>
Expected result:
----------------
1
Actual result:
--------------
Parse error: parse error, expecting
T_ENDSWITCH' or T_CASE' or
`T_DEFAULT' in .../test.php on line 4
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=25667&edit=1