PHP Strangeness

Okay, so I’m using PHP Version 4.3.8 and I’m happily coding along until I get to this:


$PICS_IMG = 0;
// Special icon
if ($forum_id == 14)
$PICS_IMG = ( $unread_topics ) ? "http://www.googlecommunity.com/f/14n.gif" : "http://www.googlecommunity.com/f/14.gif";
// Default icon
if ($PICS_IMG == 0)
$PICS_IMG = ( $unread_topics ) ? "http://www.googlecommunity.com/f/1n.gif" : "http://www.googlecommunity.com/f/1.gif";

What do you expect to happen if $forum_id is 14? I would expect either 14n.gif or 14.gif, because once that is set, $PICS_IMG will not be 0.

But no! That’s not the case!

The expected behavior (to me) only occurs if I use if ($PICS_IMG === 0) — that is, I add an extra = sign. More info at PHP language comparison operators.

3 Responses to “PHP Strangeness”

  1. Anonymous says:

    Is your coding the reason why the Cybiko forums are down?

  2. Anonymous says:

    if ($forum_id == 14)
    { // Bracket.
    $PICS_IMG = ( $unread_topics ) ? “http://www.googlecommunity.com/f/14n.gif” : “http://www.googlecommunity.com/f/14.gif”;
    } // Another one.

  3. Moh says:

    i tried it for my forums http://www.talklifeforums.com and its not working :(

Leave a Reply