0

Here is my code for my simple function, below when I use echo and my function with a number greater than zero, the function returns true(1), when the number is less than zero, nothing happens, the code and the output of the program are attached

<?php
  function isPositive(int $number) : bool{
        return $number > 0;
    }

    echo "test\n";
    echo isPositive(1);
    echo "test\n";
    echo isPositive(-1);
    echo "test\n";

output

I expected the is Positive(-1) function to return false (0)

Marik
  • 1
  • 1
    If you print boolean `false` you'll get an empty string -> https://3v4l.org/gV2KD#v8.2.2 – Álvaro González Feb 13 '23 at 10:49
  • as pointed out above when echoing the boolean, it will be type coerced to string as empty string. You may use `var_dump` to echo the variable as is – Diego D Feb 13 '23 at 10:52

0 Answers0