0

This is something I don't understand. If I assign the variable $bool the value true, and then later in the code change it to false, the variable $bool looses its value?

FYI: This reassignment of values is happening in a function in the class.

class csvcheck {
    function booleonChange () {
        echo "<br>";
        $bool = true;
        echo "1. assignment of booleon: " . $bool ."<br>";
        $bool = false;
        echo "2. assignment of booleon: " .$bool . "<br>"; // value of $bool is lost. Why??
    }
}

$csv = new csvcheck;
$csv->booleonChange();

If this code is executed in the browser, you will see this:

  1. assignment of booleon: 1
  2. assignment of booleon:
Script47
  • 14,230
  • 4
  • 45
  • 66
fydelio
  • 932
  • 1
  • 8
  • 22

1 Answers1

3

If i remember correctly, the PHP boolean false is actually converted to an empty string rather than the value of 0 that I believe you are looking for.

Actually just looked for it, and this seems to confirm:

PHP printed boolean value is empty, why?

Community
  • 1
  • 1
jwebster
  • 628
  • 2
  • 10
  • 20