Some confusion..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
johnperkins21
Forum Contributor
Posts: 140
Joined: Mon Oct 27, 2003 4:57 pm

Some confusion..

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: Some confusion..

Post 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.
Post Reply