3

I am going crazy here. The following simple if-condition does not produce the right output.

$xxx = 1;
if($xxx == 1)
    define('DEBUG', true);
else
    define('DEBUG', false);
var_dump($xxx);
var_dump(DEBUG);
die();

Output:

int(1)
bool(false)

I see absolutely no reason why the DEBUG constant is not being set to true. PHP's type juggling should allow this if-statement. And even if I put an intval in front of the variable, it still produces false as output.

Edit 2: I copied the exact code from above into a new file and it produces the expected output. So I don't know what is going on...

5
  • 3
    the 1 in string(1) is an indication of the length of the string, not its value. try echo $vbulletin->userinfo['userid']; to see what its value actually is. Commented Apr 21, 2011 at 15:58
  • Why don't you cast your $vbulletin->userinfo['userid'] as an int anyway? Commented Apr 21, 2011 at 15:59
  • it seems, that there is something missing in your debug output for userid: As Brian mentioned the (1) indicates the length, but usually the content follows after that. Commented Apr 21, 2011 at 16:04
  • Must be some caching issue. Must be server-side. I changed the code entirely, refreshed the page (by holding down the shift key) and it still produces the old output. Happens in all browsers. Commented Apr 21, 2011 at 16:41
  • Try a var_dump on DEBUG (or print_r(get_defined_constants());) before you define it and see what the output is in both cases. It appears that you can "redefine" if one define statement includes the is_case_sensitive flag... Commented Apr 21, 2011 at 17:03

2 Answers 2

4
var_dump($vbulletin->userinfo['userid']);

Output :

string(1)

Your string length is one, and it seems to be empty (a space ?).

Sign up to request clarification or add additional context in comments.

Comments

2
$vbulletin  = new stdClass();
$vbulletin->userinfo    = array('userid' =>  1);

if(1 == $vbulletin->userinfo['userid'])
    define('DEBUG', true);
else
    define('DEBUG', false);
var_dump(DEBUG);
echo "\n";
var_dump($vbulletin->userinfo['userid']);

There isn't anything wrong with your code. Running the above code gives me

bool(true) int(1) 

I suspect your $vbulletin->userinfo['userid'] variable has a different value to what you think it has

EDIT

When I change it to

$vbulletin->userinfo    = array('userid' =>  '1');

I get string(1) "1". You're string appears to be empty, and that's the reason it's failing.

5 Comments

A var_dump of the vbulletin variable produces string(1) "1", so I don't see it.
@reggie, Try explicitly setting the value just above the condition and see. If it work then the data in your variable is off. You can focus on it next
@reggie, just to confirm, You tried setting the value explicitly just above the IF condition and it still did not evaluate properly? At this my recommendation would be to install Eclipse + Xdebug and put on your debugger hat :)
Yes, I explicitly defined the value just above the if-statement. I am a Zend certified developer, and this issue is highly stupid and annoying me to the extreme. I can't make any sense of the results. When I paste it into a separate document that contains only code above, it works. It makes no sense.
@reggie, happens to all of us. Just start up the debugger and see what's actually in there at run time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.