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
  • 13,644
  • 4
  • 41
  • 60
fydelio
  • 831
  • 1
  • 7
  • 20

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
  • 618
  • 2
  • 10
  • 20