Page 1 of 1

Some confusion..

Posted: Thu Jun 17, 2004 10:12 pm
by johnperkins21
Sorry to hijack your thread but I'm looking at this:

Code: Select all

<?php
if(!defined('_DEBUG_'))
   define('_DEBUG_',0);
   
if(1 || _DEBUG_)
   echo $text; 
?>
And can't quite figure that out. Am I just retarded or that another way to do an if statement with no else clause? i.e.

Code: Select all

<?php
if(!defined('_DEBUG_')) {
   define('_DEBUG_',0);
}
   
if(1 || _DEBUG_) {  // that whole (1 || _DEBUG_) thing confuses me too
   echo $text; 
}
?>
Again, sorry for the hijack, I just saw that and wanted to learn.

thanks,
John


feyd|note: this topic is split from a previous thread

Re: Some confusion..

Posted: Thu Jun 17, 2004 10:22 pm
by feyd
johnperkins21 wrote:

Code: Select all

<?php
if(!defined('_DEBUG_'))
   define('_DEBUG_',0);
   
if(1 || _DEBUG_)
   echo $text; 
?>
...can't quite figure that out. Am I just retarded or that another way to do an if statement with no else clause? i.e.
those are if statements with a single line of code to execute. Braces are only required for running multiple lines under the control of an if. The following is also perfectly valid:

Code: Select all

<?php

if($foo)
  echo 'true';
else
  echo 'false';

?>

Code: Select all

<?php
if(!defined('_DEBUG_')) {
   define('_DEBUG_',0);
}
   
if(1 || _DEBUG_) {  // that whole (1 || _DEBUG_) thing confuses me too
   echo $text; 
}
?>
All I was doing here was forcing the echo to happen regardless of the status of _DEBUG_ (a constant, in this case) .. this was used to illustrate the before component of the code transformation I was writing about.