|
Posted by Jim Michaels on 02/16/06 00:15
<adrian.price@gmail.com> wrote in message
news:1140015879.961893.166540@g47g2000cwa.googlegroups.com...
> Okay. I've been staring at this for 48 hours now, with absolutely no
> luck. Every time I try to break it down further, it makes less sense.
> I've now broken this down to such a level that I can't think of any way
> this can even happen. But enough of that. Take this code:
>
$x = "( ( !$enrollment_id || !$sch_id || \"$course[state]\" !=
\"approved\" ) && !".(int)
$auth->check_perm('lms','submit_course',PERM_READ)." )";
$y = ( ( !$enrollment_id || !$sch_id || $course['state'] != 'approved'
) && !$auth->check_perm('lms','submit_course',PERM_READ) );
your $auth->check_perm() is returning an int instead of true or false. I
hope it is returning either 0 or a nonzero value where 0 is interpreted as
false.
I also hope none of your id's or $course[] are NULL.
C:\www\site tools\php\mathparse\phpdll>php
<?php print !0; ?>
^Z
1
C:\www\site tools\php\mathparse\phpdll>php
<?php print !5; ?>
^Z
<?php if (!5) print 1; else print 0; ?>
^Z
0
The "no result" was actually the result false and must be eventually tested
with an if to do something useful.
> debug($x,$y);
>
> if ( $y )
> debug($x,$y);
>
> if ( ( !$enrollment_id || !$sch_id || $course['state'] != 'approved' )
> && !$auth->check_perm('lms','submit_course',PERM_READ) )
> { /* real code here */ }
>
>
> $auth->check_perm returns a boolean. In this context, $enrollment_id
> and $sch_id are provided and non-zero, and $course['state'] =
> "approved". The function debug() spits out all the provided arguments
> along with some debugging info, and serves as a breakpoint. Now. Out of
> 150 users of this system, 4 have experienced an issue where, when that
> if should be false, it comes out true, reliably, on the server and my
> test platform. There's a lot of background information, some of which I
> can provide (though I have to be somewhat vague, as this is proprietary
> code), but I don't think I need to, and I'll explain why:
>
> If you leave the first breakpoint in, you get this:
> Debugging: array (
> 0 => '( ( !36 || !19 || "approved" != "approved" ) && !0 )',
> 1 => false,
> )
>
> If you comment out the first breakpoint, it breaks inside the if
> statement, even though it just said the value in the if expression is
> false:
> Debugging: array (
> 0 => '( ( ! || ! || "approved" != "approved" ) && !0 )',
> 1 => true,
> )
>
> So, my question is, how can the values referenced in the assignment of
> $x and $y change based on whether or not those variables, or variables
> assigned using data from those variables, are in an if statement? If
> you can explain that to me, I'd be thrilled, because I have a headache
> the size of siberia right now!
>
> (The code above is obviously incomplete, but it is copy-and-pasted from
> the source file unaltered, save for commenting out the code at the very
> end. And I don't really see how any other code in the file could affect
> it in this situation, but obviously something is.)
>
> If you can give even a clue or a direction to look in, I'd hugely
> appreciate it!!!
>
[Back to original message]
|