fastix®: andere Möglichkeit für Sprungmarke

Beitrag lesen

Moin!

woraus liest du das?

Verdammt. Falsche Programmiersprache oder schlechtes Lehrbuch... ich weiß es jetzt auch nicht.

Jedenfalls fast Du Recht, wie folgender kleiner Test ergibt:

<?php  
error_reporting(E_ALL);  
  
print "\nfalse AND foo()? ";  
if (false AND foo()) {;}  
  
print "\n\ntrue AND foo()? ";  
if (true AND foo()) {;}  
  
print "\n\nfalse && foo()? ";  
if (false && foo()) {;}  
  
print "\n\ntrue && foo()? ";  
if (true && foo()) {;}  
  
print "\n\nfalse or foo()? ";  
if (false or foo()) {;}  
  
print "\n\ntrue or foo()? ";  
if (true or foo()) {;}  
  
print "\n\nfalse || foo()? ";  
if (false || foo()) {;}  
  
print "\n\ntrue || foo()? ";  
if (true || foo()) {;}  
  
function foo() {  
   print "foo!";  
   return true;  
}  
print "\n\n";  
?>  

false AND foo()?

true AND foo()? foo!

false && foo()?

true && foo()? foo!

false or foo()? foo!

true or foo()?

false || foo()? foo!

true || foo()?

Das bedeutet - entgegen meiner Irrung - dass der rechte Vergleich nicht mehr stattfindet (foo() nicht ausgeführt wird) wenn die Bedingung erfüllt ist oder nicht mehr erfüllt werden kann.

MFFG (Mit freundlich- friedfertigem Grinsen)

fastix