-
Notifications
You must be signed in to change notification settings - Fork 1
BoolValue
Mistralys edited this page Apr 29, 2021
·
1 revision
This provides one-way boolean values (aka sticky booleans), to handle cases where a boolean value may be flipped, but just once.
-
valBoolTrue()
- Starts offfalse
, will staytrue
if set totrue
once. -
valBoolFalse()
- Starts offtrue
, will stayfalse
if set tofalse
once.
Consider the following loop:
$hasEmpty = false;
foreach($items as $item) {
if(empty($item)) {
$hasEmpty = true;
}
}
The if
is needed to ensure that $hasEmpty
is only set to true once.
This can be simplified with a boolean true value:
$hasEmpty = valBoolTrue(); // Starts off as false
foreach($items as $item) {
$hasEmpty->set(empty($item)); // Will stay true if set to true once
}
Once the value has been set to true, it will stay true, even if set to false afterwards.
The sister function is valBoolFalse()
works in the exact opposite way.
New here?
Have a look at the overview for a list of all helper classes available in the package.
Table of contents
Find the current page in the collapsible "Pages" list above, and expand the page, to view a table of contents.