Re: PHP 4.0 Bug #8582: normal if nested in alternate if gives parse error
| From: | chrisv at b0rked dot dhs dot org | Date: | Mon, 08 Jan 2001 01:41:23 +0000 |
| Subject: | Re: PHP 4.0 Bug #8582: normal if nested in alternate if gives parse error | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-43308@lists.php.net to get a copy of this message | ||
> From: wojas@vvtp.nl
> Operating system: Linux
> PHP version: 4.0.3pl1
> PHP Bug Type: Scripting Engine problem
> Bug description: normal if nested in alternate if gives parse error
>
> The following php code gives a parse error at the 'else:'
>
> <?php
> if(1==1):
> echo "ok so far<p>";
> if(1==1) echo "error here!";
> else:
> echo "Not possible";
> endif;
> ?>
>
> It looks like php thinks the 'else:' is part of the second
> if construct; the following code works:
>
> <?php
> if(1==1):
> echo "ok so far<p>";
> if(1==1) echo "error here!";
> echo "void";
> else:
> echo "Not possible";
> endif;
> ?>
>
> Tested with 4.0.3pl1, 4.0.4RC3 and 3.0.18 on debian woody and potato.
>
Your else is ambiguous, so the parser does it's best at deciding where it
should go. In your case, it decides that the else is supposed to be part
of your nested if, but also knows that the : shouldn't be there. Eliminate
the ambiguous else in there and it should work fine -- use braces to block
off code or use the alternate style if everywhere.
if (1 == 1) {
echo "ok so far";
if (1 == 1) echo "error here!";
} else {
echo "not possible";
}
or
if (1 == 1):
echo "ok so far";
if (1 == 1): echo "error here"; endif;
else:
echo "not possible";
endif;
Chris
>
>
> --
> Edit Bug report at: http://bugs.php.net/?id=8582&edit=1
>
>
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
> For additional commands, e-mail: php-dev-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>