Re: nested if parse error

From: Date: Fri, 31 May 2002 06:26:04 +0000
Subject: Re: nested if parse error
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-100057@lists.php.net to get a copy of this message
> > could somebody explain me please what is wrong with this > > piece of code? > > <? > > if (1): > > if (1) echo "hello"; > > else: > > endif; > > ?> > > Well, first off you've broken the golden rule, which is: Don't mix the :-type syntax with the {}-type or completely bare syntaxes. > > In more detail: on reaching the "else", PHP matches it with the nearest preceding if; this is the "If (1) echo ..." line, which isn't using :-type syntax, so it expects the else also not to use :-type syntax -- so the : is a parse error. now it's clear to me anyway it's funny that this works fine :-) <? if (1): if (1) echo "hello"; $a = 1; // here can be anything else else: endif; ?>

« previous php.general (#100057) next »