Skip to content

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.

Usage

  • valBoolTrue() - Starts off false, will stay true if set to true once.
  • valBoolFalse()- Starts off true, will stay false if set to false once.

Illustration

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.

Clone this wiki locally