Forum PHP 2017

Voting

Please answer this simple SPAM challenge: eight minus five?
(Example: nine)

The Note You're Voting On

niels dot laukens at tijd dot com
12 years ago
For the people that know C: php uses operator short circuit evaluation. That means that as soon as it knows the outcome, it'll stop processing.

<?php
if ( FALSE && some_function() )
    echo
"something";
   
// some_function() will not be called, since the first operand evaluates to false
?>

This comes in handy for situations like this:

<?php
if ( file_exists($filename) && filemtime($filename) > time() )
   
do_something();
   
// filemtime will never give a file-not-found-error, since php will stop evaluating if file_exists returns false
?>

<< Back to user notes page

To Top