Jump to content
Larry Ullman's Book Forums

Recommended Posts

Please would you guys clarify something for me.

 

If a variable is set to FALSE, i.e. $test = FALSE, that doesn't mean the word false does it? It means FALSE as in the opposite to TRUE.

 

Now if you do:

 

if($test) {and so on...

 

This will not pass the 'if' test as the variable is set to FALSE. What if it's set to TRUE? I'm not clear on the FALSE, TRUE bit of variables.

 

Thanks

Paul

Link to comment
Share on other sites

Yes your basically correct.

 

$test = FALSE; // the variable is 'not true' in a sense. This would fail an if ($test) statement

 

$test = 'false' // would be the word 'false'

 

if $test = true;

 

if ($test) { // then the variable test exists and the if statement is satisfied meaning you can run your code
      // Do something here
}

 

Hope that clears it up for you

  • Upvote 1
Link to comment
Share on other sites

Thanks gents.

 

So the statement

if ($test)

just tests that a variable exists? But what, for a variable, does 'exist' mean. NULL, TRUE, FALSE, number or text? What's it's default 'value'. Is it NULL?

 

If you're wondering why I'm banging on about this I'm on script 16.6, lines 16 and 50. I understand what line 16 does, but does it have to be FALSE, could it just as well be NULL?

Link to comment
Share on other sites

No, that conditional will only be true if $test has a "true" value, meaning it exists and isn't equal to false or an empty string or 0 or NULL. If you want to test for a variable's existence, you'd use isset().

 

 

 

Variables do not have default values in PHP.

 

As for Script 16.6, without looking at the script, I'm fairly sure it would also work if you set the variable equal to NULL.

Link to comment
Share on other sites

 Share

×
×
  • Create New...