Back to browse
GitHub Repository

Lightweight abstract classes for building immutable PHP objects.

11 starsPHP

ImmutableBase – Strict immutable data objects for PHP

by bill402099·Mar 7, 2026·2 points·0 comments

AI Analysis

●●SolidBig BrainNiche Gem

Attribute-driven null handling and SVO type narrowing outthinks PHP readonly.

Strengths
  • Per-property behavioral attributes (#[Strict], #[Lax]) dodge the class-level immutability choice
  • SVO type narrowing enforces invariants through type hierarchy, not runtime checks
  • Bundled CLI tooling (cache pre-warming, auto-doc generation) shows thoughtful DX
Weaknesses
  • PHP immutability is a niche constraint; Laravel/Symfony already have DTO packages
  • Requires framework integration — adoption depends on ecosystem buy-in
Target Audience

PHP backend developers managing data integrity

Similar To

Spatie Data Transfer Object · Laravel Data · Symfony Component

Post Description

Hi HN, I built this because PHP's `readonly` keyword isn't enough. It prevents reassignment but doesn't enforce type-safe construction, nested object validation, or consistent null handling across your data layer.

ImmutableBase takes a different approach: you extend one of three base classes (DTO, VO, or SVO — each with different strictness guarantees) and all validation happens at construction time. Your objects are either valid or they don't exist.

A few things that might be interesting to this crowd: - Behavioral attributes (`#[Strict]`, `#[Lax]`, `#[SkipOnNull]`, `#[KeepOnNull]`) let you control null/missing value handling per property rather than per class - SVO (Single Value Object) supports type narrowing with automatic validation chaining — think of it as a value object that enforces its own invariants through the type hierarchy - CLI tools: `ib-cacher` for pre-warming validation cache, `ib-writer` for auto-generating Markdown docs of your entire object hierarchy - No magic methods, no naming conventions — everything is explicit and IDE-visible

Requires PHP 8.4+. I'm the sole author and maintainer. Used in production at enterprise scale in Taiwan. Happy to discuss any design decisions — there are some deliberately controversial ones in there.

Feedback welcome.

Similar Projects

Developer Tools●●Solid

Django-Modern-Rest

Django REST framework rebuilt for async Python with zero sync_to_async calls inside.

SlickBig Brain
sobolevn
621mo ago
Developer Tools●●Solid

API-pilot – deterministic API key resolution with runtime validation

Deterministic fallback order (ENV → .env → vault) plus an opt-in validation mode and a strict CI-friendly option is a practical combo I wish I'd had in several projects. The doctor CLI that lists found keys and minimal provider probes (e.g., GET /v1/models for OpenAI) is a nice touch — useful for catching bad tokens before a pipeline runs. It’s not reinventing secret managers, but the zero-deps, stdlib-only approach and CI strictness make it an immediately usable tool for small teams.

Niche GemSolve My ProblemShip It
avi7777
114mo ago