public static function ToBoolean($e, $defaultIfEmptyOrNull = false) { if (!H::IsBoolean($defaultIfEmptyOrNull)) { throw new InvalidArgumentException("defaultIfEmptyOrNull argument MUST be boolean true|false"); } if (H::IsBoolean($e)) { return $e; } $strVal = (string) $e; $intVal = (int) $e; $floatVal = (double) $e; if ($strVal == "true" || $strVal == "1") { return true; } if ($strVal == "false" || $strVal == "0") { return false; } $isNullOrEmpty = $e === null || strlen($strVal) == 0 || $intVal == 0 || $floatVal == 0.0; if ($isNullOrEmpty) { return $defaultIfEmptyOrNull; } else { return !$defaultIfEmptyOrNull; } }