Re: [PHP] nested if parse error

2002-05-31 Thread Miroslav Figlar

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



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] nested if parse error

2002-05-31 Thread Ford, Mike [LSS]

 -Original Message-
 From: Miroslav Figlar [mailto:[EMAIL PROTECTED]]
 Sent: 31 May 2002 07:26
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] nested if parse error
 
 
 anyway it's funny that this works fine :-)
 ?
 if (1):
 if (1) echo hello;
 $a = 1;// here can be anything else
 else:
 endif;
 ?

Nope, that makes perfect sense too.  Think about where your second if(1) terminates -- 
is it still open when the parser reaches the else:?

As I said before, it just gets way too confusing if you try to mix the :-type syntax 
with anything else: if you use it at all, use it for *everything*.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] nested if parse error

2002-05-30 Thread Cal Evans

if (1){
if (1) {echo hello;}
} else { }
?

*
* Cal Evans
* Journeyman Programmer
* Techno-Mage
* http://www.calevans.com
*
 

-Original Message-
From: Miroslav Figlar [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 30, 2002 7:05 AM
To: [EMAIL PROTECTED]
Subject: [PHP] nested if parse error


could somebody explain me please what is wrong with this piece of code?
?
if (1):
if (1) echo hello;
else:
endif;
?

it gives me parse error on line 4

this works fine (no parse error):
?
if (1):
else:
if (1) echo hello;
endif;
?

thank you

miro



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] nested if parse error

2002-05-30 Thread James Holden

I think coding without the use of brackets and line seperation will drive
you mad!

A working copy of your code:
?
if (1):
if (1): echo hello;
else:
endif;
endif;
?


This in my humble op is so much neater and you can debug this in a second.

if (1){
if (1) {
echo Hello;
}
} else {
}





- James
--
W: www.londontown.com
@: [EMAIL PROTECTED]
--

-Original Message-
From: Miroslav Figlar [mailto:[EMAIL PROTECTED]]
Sent: 30 May 2002 13:05
To: [EMAIL PROTECTED]
Subject: [PHP] nested if parse error


could somebody explain me please what is wrong with this piece of code?
?
if (1):
if (1) echo hello;
else:
endif;
?

it gives me parse error on line 4

this works fine (no parse error):
?
if (1):
else:
if (1) echo hello;
endif;
?

thank you

miro



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] nested if parse error

2002-05-30 Thread Ford, Mike [LSS]

 -Original Message-
 From: Miroslav Figlar [mailto:[EMAIL PROTECTED]]
 Sent: 30 May 2002 13:05
 To: [EMAIL PROTECTED]
 Subject: [PHP] nested if parse error


 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.

Using :-type syntax, you *must* write this as:

 if (1):
 if (1):
 echo hello;
 endif;
 else:
 endif;

 this works fine (no parse error):
 ?
 if (1):
 else:
 if (1) echo hello;
 endif;
 ?

This is because the else now matches the first if (1):, which uses :-type syntax, 
so the else is expected to have a : after it, which it does -- so no parse error.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php