PHPackages                             michael-rubel/nullify - 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. michael-rubel/nullify

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

michael-rubel/nullify
=====================

Convert empty data of any type to null.

1.0.3(2y ago)16271MITPHPPHP ^8.0

Since Nov 30Pushed 1y ago1 watchersCompare

[ Source](https://github.com/michael-rubel/nullify)[ Packagist](https://packagist.org/packages/michael-rubel/nullify)[ Docs](https://github.com/michael-rubel/nullify)[ Fund](https://paypal.com/donate/?hosted_button_id=KHLEL8PFS4AXJ)[ RSS](/packages/michael-rubel-nullify/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (7)Used By (0)

[![Convert empty data of any type to null](https://user-images.githubusercontent.com/37669560/204819769-a4cf19ef-dec2-438a-aed7-b485206cb8e6.png)](https://user-images.githubusercontent.com/37669560/204819769-a4cf19ef-dec2-438a-aed7-b485206cb8e6.png)

Nullify
=======

[](#nullify)

[![tests](https://github.com/michael-rubel/nullify/actions/workflows/run-tests.yml/badge.svg)](https://github.com/michael-rubel/nullify/actions/workflows/run-tests.yml)[![infection](https://github.com/michael-rubel/nullify/actions/workflows/infection.yml/badge.svg)](https://github.com/michael-rubel/nullify/actions/workflows/infection.yml)[![backward-compat](https://github.com/michael-rubel/nullify/actions/workflows/bc-check.yml/badge.svg)](https://github.com/michael-rubel/nullify/actions/workflows/bc-check.yml)[![phpstan](https://github.com/michael-rubel/nullify/actions/workflows/phpstan.yml/badge.svg)](https://github.com/michael-rubel/nullify/actions/workflows/phpstan.yml)

A plain PHP class to convert empty data of any type to `null`

PHP `^8.0` is required to use this class.

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

[](#installation)

```
composer require michael-rubel/nullify
```

Usage
-----

[](#usage)

```
use MichaelRubel\Nullify\Nullify;

Nullify::the($value);
```

- **Note:** the class checks also nested [iterables](https://www.php.net/manual/en/function.is-iterable.php) and [ArrayAccess](https://www.php.net/manual/en/class.arrayaccess.php) objects.

Examples
--------

[](#examples)

```
$value = null;
Nullify::the($value); // null

$value = '';
Nullify::the($value); // null

$value = [];
Nullify::the($value); // null

$value = (object) [];
Nullify::the($value); // null

$value = new \stdClass;
Nullify::the($value); // null
```

---

⚡ Check nested elements:

```
$values = new Collection([
    'valid'        => true,
    'empty_array'  => [],
    'empty_string' => '',
    'collection'   => new Collection([
        'invalid' => new \stdClass,
    ])
]);

Nullify::the($values);

// Illuminate\Support\Collection^ {#459
//   #items: array:4 [
//     "valid" => true
//     "empty_array" => null
//     "empty_string" => null
//     "collection" => Illuminate\Support\Collection^ {#461
//       #items: array:1 [
//         "invalid" => null
//       ]
//       #escapeWhenCastingToString: false
//     }
//   ]
//   #escapeWhenCastingToString: false
// }
```

---

📚 If you use [Laravel Collections](https://laravel.com/docs/master/collections), you can make a macro:

```
Collection::macro('nullify', function () {
    return $this->map(fn ($value) => Nullify::the($value));
});

collect(['', [], (object) [], new \stdClass, '✔'])
    ->nullify()
    ->toArray(); // [0 => null, 1 => null, 2 => null, 3 => null, 4 => '✔']
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96% 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

Every ~157 days

Total

4

Last Release

791d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c060c69332d50a7cb290529ad84a7f216dec94d59950db7446dc93208787083?d=identicon)[michael-rubel](/maintainers/michael-rubel)

---

Top Contributors

[![michael-rubel](https://avatars.githubusercontent.com/u/37669560?v=4)](https://github.com/michael-rubel "michael-rubel (24 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

michael-rubelnullify

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/michael-rubel-nullify/health.svg)

```
[![Health](https://phpackages.com/badges/michael-rubel-nullify/health.svg)](https://phpackages.com/packages/michael-rubel-nullify)
```

###  Alternatives

[michael-rubel/laravel-couponables

This package provides polymorphic coupon functionality for your Laravel application.

19590.7k1](/packages/michael-rubel-laravel-couponables)[michael-rubel/laravel-value-objects

It is an example template for Laravel packages. Fill or change it the way you like.

20136.8k2](/packages/michael-rubel-laravel-value-objects)[michael-rubel/laravel-enhanced-container

This package provides DX tweaks for Service Container in Laravel.

88110.7k3](/packages/michael-rubel-laravel-enhanced-container)[michael-rubel/laravel-formatters

This package is a collection of classes you can use to standardize data formats in your Laravel application. It uses the Service Container to easily extend or override the formatter classes.

9491.6k4](/packages/michael-rubel-laravel-formatters)[michael-rubel/laravel-enhanced-pipeline

Laravel Pipeline with DB transaction support, events and additional methods.

5521.0k](/packages/michael-rubel-laravel-enhanced-pipeline)[jrmadsen67/laravel-feature-test-generator

Cascading model updates for Laravel.

214.0k](/packages/jrmadsen67-laravel-feature-test-generator)

PHPackages © 2026

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