(PHP 7, PHP 8)
The SplBool class is used to enforce strong typing of the bool type.
SplBool extends SplEnum {
/* Constants */
public const boolean __default = false;
public const boolean false = false;
public const boolean true = true;
/* Methods */
public function __construct ([ bool $initial_value = false ])
final public function &__invoke(): bool
/* Inherited methods */
public array SplEnum::getConstList ([ bool $include_default = false ])
}
SplBool::__default
SplBool::false
SplBool::true
<?php
$true = new SplBool(true);
if ($true()) {
echo "TRUE\n";
}
$false = new SplBool;
if ($false) {
echo "FALSE\n";
}
The above example will output:
TRUE
- SplType::__construct — Creates a new value of some type
- SplEnum::getConstList — Returns all consts (possible values) as an array.
- SplBool::__invoke — Invoke object like a method