PHPackages                             mpscholten/value-or-default - 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. mpscholten/value-or-default

ActiveLibrary

mpscholten/value-or-default
===========================

Simple default values for your code

1.0.0(10y ago)029[1 issues](https://github.com/mpscholten/value-or-default/issues)MITPHPPHP &gt;=5.4

Since Oct 5Pushed 10y ago1 watchersCompare

[ Source](https://github.com/mpscholten/value-or-default)[ Packagist](https://packagist.org/packages/mpscholten/value-or-default)[ RSS](/packages/mpscholten-value-or-default/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

ValueOrDefault
==============

[](#valueordefault)

[![Latest Stable Version](https://camo.githubusercontent.com/e734bc8f3edd2f88896e3ccca1bf2c952a920c5cb90efdf6d62835d2a603d615/68747470733a2f2f706f7365722e707567782e6f72672f6d707363686f6c74656e2f76616c75652d6f722d64656661756c742f76657273696f6e)](https://packagist.org/packages/mpscholten/value-or-default) [![License](https://camo.githubusercontent.com/b78afa15643114fb262b7b6dfea81b11dbd9a791d94e2e17254f134adee1aed4/68747470733a2f2f706f7365722e707567782e6f72672f6d707363686f6c74656e2f76616c75652d6f722d64656661756c742f6c6963656e7365)](https://packagist.org/packages/mpscholten/value-or-default) [![Circle CI](https://camo.githubusercontent.com/92160a542e554ec7381858f9ae94d2dc4b3ff571b66ad5abcc7b415daeb32279/68747470733a2f2f636972636c6563692e636f6d2f67682f6d707363686f6c74656e2f76616c75652d6f722d64656661756c742e7376673f7374796c653d736869656c64)](https://circleci.com/gh/mpscholten/value-or-default)

Simple default values for your php code.

### Get started

[](#get-started)

Install via composer

```
composer install mpscholten/value-or-default

```

### Basic Usage

[](#basic-usage)

```
// Env variables
$tempDir = \MPScholten\valueOrDefault($_ENV['TEMP_DIR'], '/tmp');
// $tempDir is now either $_ENV['TEMP_DIR'] or '/tmp' dependending on whether $_ENV['TEMP_DIR'] is set

// JSON input
$user = json_decode(...);
$userName = \MPScholten\valueOrDefault($user['name'], 'n/a');
// $userName is now either $user['name'] or 'n/a' depending on whether $user['name'] is set and non-null

// Null values
$value = null;
\MPScholten\valueOrDefault($value, 0); // returns 0 because $value == null
```

### Tests

[](#tests)

You can run the `phpunit` suite with `make`

```
make tests

```

### Contributing

[](#contributing)

Feel free to send pull requests!

###  Health Score

26

—

LowBetter than 46% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

3820d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/00ab5df48f62845d1e549e99c62eff4379d692bf8721f98dd4ee00275723692a?d=identicon)[mpscholten](/maintainers/mpscholten)

---

Top Contributors

[![mpscholten](https://avatars.githubusercontent.com/u/2072185?v=4)](https://github.com/mpscholten "mpscholten (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mpscholten-value-or-default/health.svg)

```
[![Health](https://phpackages.com/badges/mpscholten-value-or-default/health.svg)](https://phpackages.com/packages/mpscholten-value-or-default)
```

PHPackages © 2026

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