-1

I was reading PHP's Array man and I saw this:

<?php
// fill an array with all items from a directory
$handle = opendir('.');
while (false !== ($file = readdir($handle))) {
    $files[] = $file;
}
closedir($handle); 
?>

In the readdir man page, it says "Correctly way of looping".

I'd like to know if there's a difference between X !== false and false !== X. Thanks!

JorgeeFG
  • 4,812
  • 8
  • 48
  • 78
  • Duplicates: http://stackoverflow.com/q/9177903/1409082 http://stackoverflow.com/q/11181802/1409082 http://stackoverflow.com/q/7261117/1409082 http://stackoverflow.com/q/10656419/1409082 http://stackoverflow.com/q/12939684/1409082 and certainly other questions. – Jocelyn Nov 07 '12 at 14:47
  • possible duplicate of [Why do some experienced programmers write expressions this way?](http://stackoverflow.com/questions/3309089/why-do-some-experienced-programmers-write-expressions-this-way) – Andy Mar 04 '14 at 19:32

2 Answers2

3

No, there's no difference. The reason you'll sometimes see false == x instead of x == false is that it helps prevent accidentally typing x = false which is permissible in an if or loop structure but is probably not what you want. false = x is nonsensical, and will generate an error instead of silently assigning something.

Telgin
  • 1,539
  • 9
  • 10
1

No it's the same

writing this

false !== X

is also known as "Yoda condition" :) Very useful when you want to avoid unexpected assignments (using = instead of ==)

Gianluca Ghettini
  • 9,354
  • 14
  • 63
  • 132