On Wednesday 16 January 2002 17:25, you wrote: I'm sorry, I think I was confusing languages. PHP does do lazy evaluation. If the left side is false the right side won't be evaluated. I've attached some code, it ain't really neat & tidy but it's effective and will show you how it works. Just run it
> aha! see, i didn't understand the whole picture. so, let me see if i can > create another question. suppose > > if (($a_good = ($a == 'a')) && ($b_good = ($b == 'b'))) blahblahblah(); > > are you saying, that $b_good should always have the result of ($b == 'b') > even if $a != 'a'? that's not what my test shows (hi bogdan :) > > so, is there something other than && that forces the other half to be > evaluated? > > interesting... > mike > > on 8/23/01 5:19 PM, TD - Sales International Holland B.V. at > [EMAIL PROTECTED] > > wrote: > > On Wednesday 16 January 2002 16:18, you wrote: > > > > I think the cause is, which is lacking in the reply below, that if you > > have like > > if ((function1(val, val)) && (function2(val, val)) blabla(); > > > > you still want function2 to be executed because it does things necessary > > for your script, however, if one of them returns false you don't want > > blabla() to be executed. If that isn't the case you should use or or one > > of the other operators > > > > not too sure about that tho' but i'm sure I'll be corrected if that isn't > > the case :-) > > > >> on 1/16/02 5:57 AM, Miles Thompson at [EMAIL PROTECTED] wrote: > >>> For "or" statements it does, but not && or xor. I don't know about you, > >>> but I wouldn't want lazy evaluation on a conditional statement > >>> involving "and". > >> > >> i'm new to all this stuff, so i'll bite. hopefully someone can explain > >> what i'm missing. > >> > >> if i have a statement like > >> > >> if (($a == 'a') && ($b == 'b')) blahblahblah(); > >> > >> and, $a != 'a'. > >> > >> why should php even look at the value for $b while evaluating this line? > >> shouldn't the if fail after evaluating $a? > >> > >> thanks, > >> mike > >> > >> -- mike cullerton michaelc at cullerton dot com > > -- mike cullerton michaelc at cullerton dot com
<? /* This is to test whether or not && evaluates both sides if the left side is false */ function tr() { print "This function returns true<BR>\n"; return TRUE; } function fl() { print "This function returns false<BR>\n"; return FALSE; } print "<HTML><HEAD><TITLE>The Logical Operator && Test</TITLE></HEAD><BODY><H1>The Logical Operator && Test</H1>\n"; print "<CENTER>True && True then echo succes<BR>\n"; if (tr() && tr()) echo "Succes<BR>\n"; print "<HR>\n"; print "True && False then echo succes<BR>\n"; if (tr() && fl()) echo "Succes<BR>\n"; print "<HR>\n"; print "<CENTER>False && True then echo succes<BR>\n"; if (fl() && tr()) echo "Succes<BR>\n"; print "<HR>\n"; print "<CENTER>False && False then echo succes<BR>\n"; if (fl() && fl()) echo "Succes<BR>\n"; print "<HR>\n"; print "</CENTER></BODY></HTML>"; ?>
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]