Hi Tim,

>
> <?php
>  if (false)
>   ?>Hello<?php
> ?>
>
> or
>
> <?php
>  if (true)
>   ?>Hello<?php
> ?>
>

at first, I'd like to point out that semicolon as a statement separator is
not required before end of the
php fragment and is supplied automatically during parsing. That's why the
if-statements initiated above
are evaluated independently of the rest of code and 'Hello' is always on
output. It is equivalent to:

 <?php
  if (false);
   ?>Hello<?php
 ?>

 or

 <?php
  if (true);
   ?>Hello<?php
 ?>


> <?php
>  if (false)
>   ?>Hello<?php
>  else
>   echo "Hi";
>
>  echo " World\n";
> ?>
>

For this reason the above fragment generates parse error because 'if' is
evaluated separately and then
'else' is unexpected. If You want to interlard the php control blocks (in
case of if, switch, for, etc.
statements) You must use colon syntax as following:

 <?php
  if (false):
   ?>Hello<?php
  else:
   echo "Hi";
 endif; //this is is the end of the if statement; its required when using
colon syntax

  echo " World\n";
 ?>

Hope it helps,
Mike

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

Reply via email to