Results 1 to 3 of 3

Thread: [resolved] is there something I don't understand so that 'none' == 1

  1. #1

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Resolved [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
    ?
    'What's this bit for anyway?
    For Jono

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.

  3. #3

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Re: is there something I don't understand so that 'none' == 1

    Quote 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.
    ?
    'What's this bit for anyway?
    For Jono

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width