PHPackages                             techins/parse-bool - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. techins/parse-bool

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

techins/parse-bool
==================

Convert A string Value Into Boolean

1.0.0(1y ago)071MITPHP

Since Sep 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/TechIns-Software/parse-bool)[ Packagist](https://packagist.org/packages/techins/parse-bool)[ RSS](/packages/techins-parse-bool/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

ParseBool
=========

[](#parsebool)

`ParseBool` is a PHP class designed to facilitate the parsing and validation of boolean values from various input types. It simplifies the process of interpreting values that can be represented as true or false, making your code cleaner and more reliable.

Purpose
-------

[](#purpose)

The primary purpose of the `ParseBool` class is to convert different data types—such as strings, numbers, and booleans—into a consistent boolean output (`true` or `false`). This is particularly useful when dealing with user input or data from external sources, where the representation of boolean values can vary.

Installation
------------

[](#installation)

You can include the `ParseBool` class in your project by copying the `ParseBool.php` file into your desired directory.

Usage
-----

[](#usage)

### Parsing and Casting value into Boolean

[](#parsing-and-casting-value-into-boolean)

To use the `ParseBool` class, simply call the `parseBool` method with your value as an argument.

### Example

[](#example)

```
use Techins\ParseBool\ParseBool;

$value1 = ParseBool::parseBool('yes');  // Returns true
$value2 = ParseBool::parseBool(0);       // Returns false
$value3 = ParseBool::parseBool(true);    // Returns true
$value4 = ParseBool::parseBool('off');    // Returns false

$value4 = ParseBool::parseBool('dfsafsdfsdfds');    // Returns false
$value4 = ParseBool::parseBool('dfsafsdfsdfds',true);    // Throws exception look bellow
```

### Strict checking

[](#strict-checking)

Upon strinct checking if the provided value cannot be interpreted as a boolean, a `ValueNotBooleanOneException` will be thrown. You should wrap your calls in a try-catch block to handle this exception gracefully:

```
try {
    // Checklbox Value
    $input = $_POST['checkbox_val'];
    $result = ParseBool::parseBool($input,true);
} catch (ValueNotBooleanOneException $e) {
    // Handle the exception
}
```

#### Input validation

[](#input-validation)

You can also validate a boolean value (for example if value is a checked checkbox)

```
$value1 = ParseBool::validateBooleableValue('yes');  // Returns true
$value2 = ParseBool::validateBooleableValue(0);       // Returns true
$value3 = ParseBool::validateBooleableValue(true);    // Returns true
$value4 = ParseBool::validateBooleableValue('off');    // Returns true
$value3 = ParseBool::validateBooleableValue(false);    // Returns true
$value3 = ParseBool::validateBooleableValue('true');    // Returns true

$value5 = ParseBool::validateBooleableValue('ddsasadsa');  // Returns false
$value6 = ParseBool::validateBooleableValue(-1);       // Returns false
$value6 = ParseBool::validateBooleableValue("");       // Returns false

```

Valid Boolean Values
--------------------

[](#valid-boolean-values)

The following values are considered valid and will be converted to `true`:

- `1`
- `true`
- `'on'`
- `'yes'`
- `'true'`

The following values are considered valid and will be converted to `false`:

- `0`
- `false`
- `'off'`
- `'no'`
- `'false'`
- `f`

Any other values will result in a `ValueNotBooleanOneException`.

Usage upon checkboxes
---------------------

[](#usage-upon-checkboxes)

Assuming we have thius form

```

```

You can use `validateBooleableValue` to validate whether checkbox is checked.

```

$checked = ParseBool::parseBool($_POST['check']??false);

```

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

Contributing
------------

[](#contributing)

Contributions are welcome! Please submit a pull request or open an issue for any enhancements or bug fixes.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

602d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d57c64b259195a64cbad626742deb35aa86219fdfebc2a3f40c23bb825ede735?d=identicon)[pc-magas](/maintainers/pc-magas)

![](https://www.gravatar.com/avatar/d2fb65a184a4f0a1e92faa3780a58049bd408c33446609f2ff0d68fd65f466fb?d=identicon)[ChristosBaztekas](/maintainers/ChristosBaztekas)

---

Top Contributors

[![pc-magas](https://avatars.githubusercontent.com/u/1299750?v=4)](https://github.com/pc-magas "pc-magas (7 commits)")

### Embed Badge

![Health badge](/badges/techins-parse-bool/health.svg)

```
[![Health](https://phpackages.com/badges/techins-parse-bool/health.svg)](https://phpackages.com/packages/techins-parse-bool)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
