Women in Technology

Hear us Roar

  Working with Files in PHP, Part 3
Subject:   line !== 'false'
Date:   2003-03-12 15:22:26
From:   anonymous2
The article states that you need to use the !== comparison operator:
"Without this type of comparison, the while loop would end prematurely if a directory (or filename) existed with the name of false"

I can't seem to get the loop to stop when it encounters a directory named false even if I leave out the !== and use != instead.

Using windows.

Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • line !== 'false'
    2003-03-12 16:39:03  John Coggeshall | O'Reilly Author [View]

    Although this behavior may work (not using the 'identical' comparison and just using a standard comparison) it is not to be relied on. For instance:

    $myfile = "0"; // a filename whose name is '0'
    if($myfile == false) {
    echo "$myfile is false\n";
    } else {
    echo "$myfile is true.\n";

    In this case, the string '0' will be evaluated as an integer value '0' which is in turn a boolean false. In order for this to behave properly you'd need to use the identical comparison === operator.

    • line !== 'false'
      2005-03-17 10:11:01  Cerro [View]

      I was looking for some code to list the directory content with PHP3. The problem that i had was that i had a subdirectory named 0. Since in PHP3 there is no !== operator i did like this:

      function ListDir($dir)
      if ((file_exists($dir)) && ($dh = opendir($dir)))
      while (($file = readdir($dh)) || (((string) $file == "0") || ($file != false)))

      In this case the problem directory name is "0" but you can add "false" to the condition.