PHPackages                             brick/std - 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. brick/std

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

brick/std
=========

An attempt at a standard library for PHP

0.5.0(2mo ago)444.4k↓50%3[1 PRs](https://github.com/brick/std/pulls)2MITPHPPHP ^8.2CI failing

Since Nov 6Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/brick/std)[ Packagist](https://packagist.org/packages/brick/std)[ RSS](/packages/brick-std/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (3)Versions (12)Used By (2)

Brick\\Std
==========

[](#brickstd)

[![](https://raw.githubusercontent.com/brick/brick/master/logo.png)](https://raw.githubusercontent.com/brick/brick/master/logo.png)

An attempt at a standard library for PHP.

[![Build Status](https://github.com/brick/std/workflows/CI/badge.svg)](https://github.com/brick/std/actions)[![Coverage Status](https://camo.githubusercontent.com/a4eb08a55e54b64bfcd9ac8b4ed2c5c0c9e04b5c0efe48b8e8eb15a937a46d29/68747470733a2f2f636f6465636f762e696f2f6769746875622f627269636b2f7374642f67726170682f62616467652e737667)](https://codecov.io/github/brick/std)[![Latest Stable Version](https://camo.githubusercontent.com/e768b176ad6218d2061ba69d5b0b4a76c8869210d380c08ad505ffa3634ec94c/68747470733a2f2f706f7365722e707567782e6f72672f627269636b2f7374642f762f737461626c65)](https://packagist.org/packages/brick/std)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](http://opensource.org/licenses/MIT)

Introduction
------------

[](#introduction)

The PHP internal functions are notorious for their inconsistency: inconsistent naming, inconsistent parameter order, inconsistent error handling: sometimes returning `false`, sometimes triggering an error, sometimes throwing an exception, and sometimes a mix of these. The aim of this library is mainly to provide a consistent, object-oriented wrapper around PHP native functions, that deals with inconsistencies internally to expose a cleaner API externally. Hopefully PHP will do this job one day; in the meantime, this project is a humble attempt to fill the gap.

The library will start small. Functionality will be added as needs arise. Contributions are welcome.

Project status &amp; release process
------------------------------------

[](#project-status--release-process)

The current releases are numbered `0.x.y`. When a non-breaking change is introduced (adding new methods, optimizing existing code, etc.), `y` is incremented.

**When a breaking change is introduced, a new `0.x` version cycle is always started.**

It is therefore safe to lock your project to a given release cycle, such as `0.3.*`.

If you need to upgrade to a newer release cycle, check the [release history](https://github.com/brick/std/releases)for a list of changes introduced by each further `0.x.0` version.

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

[](#installation)

This library is installable via [Composer](https://getcomposer.org/):

```
composer require brick/std
```

Requirements
------------

[](#requirements)

This library requires PHP 8.2 or later.

Overview
--------

[](#overview)

### IO

[](#io)

File I/O functionality is provided via static methods in the [FileSystem](https://github.com/brick/std/blob/master/src/Io/FileSystem.php) class. All methods throw an [IoException](https://github.com/brick/std/blob/master/src/Io/IoException.php) on failure.

*The ultimate aim of this class would be to throw fine-grained exceptions for specific cases (file already exists, destination is a directory, etc.) but this would require to analyze PHP error messages, making the library fragile to changes, and/or call several internal filesystem functions in a row, making most of the operations non-atomic. Both approaches have potentially serious drawbacks. Ideas and comments welcome.*

Method list:

- `copy()` Copies a file.
- `move()` Moves a file or a directory.
- `delete()` Deletes a file.
- `createDirectory()` Creates a directory.
- `createDirectories()` Creates a directory by creating all nonexistent parent directories first.
- `exists()` Checks whether a file or directory exists.
- `isFile()` Checks whether the path points to a regular file.
- `isDirectory()` Checks whether the path points to a directory.
- `isSymbolicLink()` Checks whether the path points to a symbolic link.
- `createSymbolicLink()` Creates a symbolic link to a target.
- `createLink()` Creates a hard link to an existing file.
- `readSymbolicLink()` Returns the target of a symbolic link.
- `getRealPath()` Returns the canonicalized absolute pathname.
- `write()` Writes data to a file.
- `read()` Reads data from a file.

### Iterator

[](#iterator)

The library ships with two handy iterator for CSV files:

#### CsvFileIterator

[](#csvfileiterator)

This iterator iterates over a CSV file, and returns an indexed array by default:

```
use Brick\Std\Iterator\CsvFileIterator;

// 1,Bob,New York
// 2,John,Los Angeles
$users = new CsvFileIterator('users.csv');

foreach ($users as [$id, $name, $city]) {
    // ...
}
```

It can also read the first line of the file that contains column names, and use them to return an associative array:

```
use Brick\Std\Iterator\CsvFileIterator;

// id,name,city
// 1,Bob,New York
// 2,John,Los Angeles
$users = new CsvFileIterator('users.csv', true);

foreach ($users as $user) {
    // $user['id'], $user['name'], $user['city']
}
```

Delimiter, enclosure and escape characters can be provided to the constructor.

#### CsvJsonFileIterator

[](#csvjsonfileiterator)

This iterator iterates over a CSV file whose fields are JSON-encoded:

```
use Brick\Std\Iterator\CsvJsonFileIterator;

// 1,"Bob",["John","Mike"]
// 2,"John",["Bob","Brad"]
$users = new CsvJsonFileIterator('users.csv');

foreach ($users as [$id, $name, $friends]) {
    // $id is an int
    // $name is a string
    // $friends is an array
}
```

The JSON-encoded fields must not contain newline characters.

### JSON

[](#json)

JSON functionality is provided by [JsonEncoder](https://github.com/brick/std/blob/master/src/Json/JsonEncoder.php) and [JsonDecoder](https://github.com/brick/std/blob/master/src/Json/JsonDecoder.php). Options are set on the encoder/decoder instance, via explicit methods. If an error occurs, a [JsonException](https://github.com/brick/std/blob/master/src/Json/JsonException.php) is thrown.

Encoding:

```
use Brick\Std\Json\JsonEncoder;

$encoder = new JsonEncoder();
$encoder->forceObject(true);

$encoder->encode(['Hello World']); // '{"0":"Hello World"}'
$encoder->encode(tmpfile()); // Brick\Std\Json\JsonException: Type is not supported
```

Decoding:

```
use Brick\Std\Json\JsonDecoder;

$decoder = new JsonDecoder();
$decoder->decodeObjectAsArray(true);

$decoder->decode('{"hello":"world"}'); // ['hello' => 'world']
$decoder->decode('{hello}'); // Brick\Std\Json\JsonException: Syntax error
```

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance84

Actively maintained with recent releases

Popularity35

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity72

Established project with proven stability

 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 ~379 days

Recently: every ~582 days

Total

9

Last Release

80d ago

PHP version history (5 changes)0.1.0PHP &gt;=7.1

0.3.0PHP &gt;=7.2

0.3.1PHP ^7.2|^8.0

0.4.0PHP ^7.3 || ^8.0

0.5.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/57189121968030f0770811b461cc92f9c19c08f5c4767292f2ede48b7277cfad?d=identicon)[BenMorel](/maintainers/BenMorel)

---

Top Contributors

[![BenMorel](https://avatars.githubusercontent.com/u/1952838?v=4)](https://github.com/BenMorel "BenMorel (121 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (1 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (1 commits)")[![su-narthur](https://avatars.githubusercontent.com/u/20328940?v=4)](https://github.com/su-narthur "su-narthur (1 commits)")

---

Tags

phpstandard-librarybrickstd

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/brick-std/health.svg)

```
[![Health](https://phpackages.com/badges/brick-std/health.svg)](https://phpackages.com/packages/brick-std)
```

###  Alternatives

[brick/math

Arbitrary-precision arithmetic library

2.1k504.0M277](/packages/brick-math)[brick/money

Money and currency library

1.9k37.9M102](/packages/brick-money)[brick/date-time

Date and time library

3623.3M61](/packages/brick-date-time)[brick/geo

GIS geometry library

245862.1k15](/packages/brick-geo)[brick/schema

Schema.org library for PHP

5163.7k1](/packages/brick-schema)[brick/reflection

Low-level tools to extend PHP reflection capabilities

23260.5k5](/packages/brick-reflection)

PHPackages © 2026

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