Skip to content
Simple default values for your php code
PHP Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/MPScholten
tests/MPScholten/Test
.gitignore
LICENSE
Makefile
README.md
circle.yml
composer.json
phpunit.xml.dist

README.md

ValueOrDefault

Latest Stable Version License Circle CI

Simple default values for your php code.

Get started

Install via composer

composer install mpscholten/value-or-default

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

You can run the phpunit suite with make

make tests

Contributing

Feel free to send pull requests!

You can’t perform that action at this time.