Shouldn’t the function return value ($checkZero) be false (boolean)?
The result of the following is ‘zero is zero’. What am I missing?
class CheckZero {
function __construct() {
$zero = 3;
if ($zero === 0) {
return true;
}
else {
return false;
}
}
}
$checkZero = new CheckZero();
if (!$checkZero) {
echo 'zero is not zero';
}
else {
echo 'zero is zero';
}
You can’t
returnfrom a class constructor. What is returned is the newly created object.If you
var_dumpthe return value, you’ll see that an object was returned:object(CheckZero)#1 (0) { }