|
-
Jan 24th, 2007, 12:24 PM
#1
Thread Starter
Fanatic Member
[resolved] is there something I don't understand so that 'none' == 1
Before we begin I should point out that the debug function does a print_r on the array, the numbers are used like error levels and are irrelivant to the question.
Code:
$this->debug("db_connect-mid:", array($this->db_conn, $this->db_used), 5);
if ($this->db_used == 'none'){
$this->debug("db_connect-used:", array($this->db_conn, $this->db_used), 4);
...
The above code deals with the value $this->db_used which is a class wide variable. It carries TRUE when the resource $this->db_conn has been successfully used to connect to the correct database.
This section of code makes the connection if it is not there. It only has the information to do this when it should logicly need to (if it is the first in the chain as everything else passes by value the content of the two class scope variable).
The debug output both before and after "if ($this->db_used == 'none')" show a value of 1
Code:
DEBUG level: 5
Class: responder
db_connect-mid:
Array
(
[0] => Resource id #5
[1] => 1
)
DEBUG level: 4
Class: responder
db_connect-used:
Array
(
[0] => Resource id #5
[1] => 1
)
How then are we dealing with code inside the IF?
It is beating me at the moment.
Last edited by Matt_T_hat; Jan 24th, 2007 at 02:10 PM.
Reason: Resolved
-
Jan 24th, 2007, 12:46 PM
#2
Re: is there something I don't understand so that 'none' == 1
It seems that for the purpose of comparison, PHP converts both terms to boolean. Integers != 0 convert to true and strings != "" convert to true, so the terms are equivalent.
To force PHP to not convert anything (in which case different types always compare false), use === instead of ==.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 24th, 2007, 02:00 PM
#3
Thread Starter
Fanatic Member
Re: is there something I don't understand so that 'none' == 1
 Originally Posted by CornedBee
It seems that for the purpose of comparison, PHP converts both terms to boolean. Integers != 0 convert to true and strings != "" convert to true, so the terms are equivalent.
To force PHP to not convert anything (in which case different types always compare false), use === instead of ==.
All for the want of a nail! One tiny character!
Thank you - it now works as I expected it to.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|