PHPackages                             nusje2000/strict-php - 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. nusje2000/strict-php

Abandoned → [thecodingmachine/safe](/?search=thecodingmachine%2Fsafe)Library

nusje2000/strict-php
====================

A wrapper for standard php functions with correct error handling and improved typing

v0.1.0(5y ago)04MITPHPCI failing

Since Jul 29Pushed 5y ago1 watchersCompare

[ Source](https://github.com/nusje2000/strict-php)[ Packagist](https://packagist.org/packages/nusje2000/strict-php)[ RSS](/packages/nusje2000-strict-php/feed)WikiDiscussions master Synced 6d ago

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

Strict PHP
==========

[](#strict-php)

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

[](#installation)

```
composer require nusje2000/strict-php
```

Why?
----

[](#why)

This package was created because of the way the default php functions behave. A lot of functions return types that are not logical. This package wraps these functions and adds correct error handling and typing to these functions.

Functions
---------

[](#functions)

### File functions

[](#file-functions)

#### exists (replaces is\_file)

[](#exists-replaces-is_file)

To check if a file exists, you can use `File::exists()`:

```
use Nusje2000\StrictPhp\File;

File::exists('path/to/file.txt');
```

#### getContents (replaces file\_get\_contents)

[](#getcontents-replaces-file_get_contents)

To retrieve contents from a file, you can use `File::getContents()`. This function will return the contents and if not possible, an exception will be thrown.

```
use Nusje2000\StrictPhp\File;

File::getContents('path/to/file.txt');
```

#### putContents (replaces file\_put\_contents)

[](#putcontents-replaces-file_put_contents)

To write contents to a file, you can use `File::putContents()`. This function will always return the amount of bytes written and if not possible, an exception will be thrown.

```
use Nusje2000\StrictPhp\File;

File::putContents('path/to/file.txt', 'contents');
```

### Directory functions

[](#directory-functions)

#### exists (replaces is\_dir)

[](#exists-replaces-is_dir)

To check if a directory exists, you can use `Directory::exists()`.

```
use Nusje2000\StrictPhp\Directory;

Directory::exists('path/to/file.txt');
```

### Json functions

[](#json-functions)

#### encode (replaces json\_encode)

[](#encode-replaces-json_encode)

To encode a variable into json, you can use `Json::encode()`. This will always return the encoded string. If the encoding fails, an exception will be thrown.

```
use Nusje2000\StrictPhp\Json;

Json::encode(['key' => 'value']);
```

#### decode (replaces json\_decode)

[](#decode-replaces-json_decode)

To decode a json formatted string, you can use `Json::decode()`. This function has multiple return types.

```
use Nusje2000\StrictPhp\Json;

Json::decode('"some-valid-json"');
```

#### decodeToObject (replaces json\_decode)

[](#decodetoobject-replaces-json_decode)

If an object is expected as return type, decodeToObject can be used to both decode and assert that the output is an object. If the output is not an instance of stdClass, an exception will be thrown.

```
use Nusje2000\StrictPhp\Json;

Json::decodeToObject('{"key": "value"}'); // stdClass { $key = 'value' }
```

#### decodeToArray (replaces json\_decode)

[](#decodetoarray-replaces-json_decode)

If an array is expected as return type, decodeToArray can be used to both decode and assert that the output is an array. If the output is not an array, an exception will be thrown.

```
use Nusje2000\StrictPhp\Json;

Json::decodeToArray('["value 1", "value 2", "value 3"]'); // ['value 1', 'value 2', 'value 3']
Json::decodeToArray('{"key": "value"}'); // ['key' => 'value']
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

2117d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17175959?v=4)[Maarten Nusteling](/maintainers/nusje2000)[@nusje2000](https://github.com/nusje2000)

---

Top Contributors

[![nusje2000](https://avatars.githubusercontent.com/u/17175959?v=4)](https://github.com/nusje2000 "nusje2000 (6 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nusje2000-strict-php/health.svg)

```
[![Health](https://phpackages.com/badges/nusje2000-strict-php/health.svg)](https://phpackages.com/packages/nusje2000-strict-php)
```

PHPackages © 2026

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