Skip to content

Commit fe3daa5

Browse files
committed
Add announcement for TypePHP v0.8.0 release, highlighting new features and improvements
1 parent 98d1362 commit fe3daa5

2 files changed

Lines changed: 196 additions & 0 deletions

File tree

‎docs/.vitepress/data/posts.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
[
2+
{
3+
"title": "TypePHP v0.8.0: Schema Composition, Conditional Parameters, and Smart Diagnostics",
4+
"url": "/docs/blog/celebrating-v0.8.0-schema-composition-and-smart-diagnostics",
5+
"date": "September 15, 2026",
6+
"readTime": "6 min read",
7+
"badge": "Release",
8+
"badgeClass": "badge-announcement",
9+
"excerpt": "Celebrating the release of v0.8.0! This release brings array shape composition, discriminator-aware union diagnostics, conditional parameters, and a zero-I/O production mode to the PHP ecosystem."
10+
},
211
{
312
"title": "When Static Analyzers Teach You the Wrong Way: The Dogma of Variance and the Pursuit of Working QA",
413
"url": "/docs/blog/when-static-analyzers-teach-the-wrong-way",
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
---
2+
title: "TypePHP v0.8.0: Schema Composition, Conditional Parameters, and Smart Diagnostics"
3+
description: "Celebrating the release of v0.8.0! This release brings array shape composition, discriminator-aware union diagnostics, conditional parameters, and a zero-I/O production mode to the PHP ecosystem."
4+
date: 2026-09-15
5+
author: Reymart Calicdan
6+
layout: doc
7+
sidebar: false
8+
aside: true
9+
prev: false
10+
next: false
11+
---
12+
13+
# TypePHP v0.8.0: Schema Composition, Conditional Parameters, and Smart Diagnostics
14+
15+
<div class="blog-post-meta" style="margin-bottom: 24px;">
16+
<span class="blog-badge badge-announcement">Release</span>
17+
<span>September 15, 2026</span>
18+
<span class="dot">•</span>
19+
<span>6 min read</span>
20+
</div>
21+
22+
Today, I am incredibly proud to announce the release of **TypePHP v0.8.0**.
23+
24+
When I started TypePHP, my goal was simple: bring true runtime type safety to modern PHP without forcing developers to abandon their existing PHPDoc annotations, compile C-extensions, or adopt proprietary attributes. I wanted the PHPStan and Psalm contracts you already write to actually mean something when your code runs in production.
25+
26+
I have already been using TypePHP in almost all of my own PHP projects and daily development workflows. It has completely transformed how I write code and making me significantly more productive and giving me absolute confidence through extreme type safety. Finally being able to rely on typed arrays and true reified generics at runtime is an absolute game changer.
27+
28+
With the release of v0.8.0, the engine has reached a remarkable level of maturity. Over **1,270 tests** and **3,300 assertions** run flawlessly under PHPStan Level MAX strictness. The engine now fluently handles some of the most advanced type algebra in the PHP ecosystem.
29+
30+
Let's dive into what makes v0.8.0 my most powerful release yet.
31+
32+
---
33+
34+
## 1. Array Shape Composition (`ShapeA & ShapeB`)
35+
36+
In modular architectures, developers frequently compose schemas using intersections. Until now, intersecting *sealed* array shapes posed a theoretical contradiction: if `ShapeA` strictly forbids extra keys, and `ShapeB` strictly forbids extra keys, how can they ever merge?
37+
38+
In v0.8.0, TypePHP introduces **Schema Composition**. When you intersect multiple array shapes or object shapes, TypePHP seamlessly merges them into a unified composite schema at runtime.
39+
40+
```php
41+
/**
42+
* @phpstan-type Identifiable array{id: positive-int}
43+
* @phpstan-type Taggable array{tags: list<string>}
44+
* @phpstan-type ArticleShape Identifiable & Taggable
45+
*
46+
* @param ArticleShape $article
47+
*/
48+
function publishArticle(array $article): void { ... }
49+
50+
// Valid: TypePHP merges the schemas into array{id: positive-int, tags: list<string>}
51+
publishArticle([
52+
'id' => 101,
53+
'tags' => ['php', 'release'],
54+
]);
55+
56+
// Invalid: The merged shape is sealed. Unexpected keys are strictly forbidden!
57+
publishArticle([
58+
'id' => 101,
59+
'tags' => ['php'],
60+
'unregistered_key' => true,
61+
]);
62+
// Throws: TypeError: Argument $article contains unsealed unexpected key 'unregistered_key'
63+
```
64+
65+
If intersected shapes declare the same key with different constraints (e.g., `score: int` and `score: positive-int`), TypePHP intelligently unifies them into a combined intersection constraint (`score: int & positive-int`).
66+
67+
---
68+
69+
## 2. Intelligent Union & Intersection Diagnostics
70+
71+
Discriminated unions (also known as tagged unions) are the industry standard for handling varying API payloads, domain events, and state machines.
72+
73+
```php
74+
/**
75+
* @param array{type: 'click', x: int, y: int}
76+
* | array{type: 'hover', element: non-empty-string} $event
77+
*/
78+
function handleEvent(array $event): void { ... }
79+
```
80+
81+
In previous versions, if you passed a `'hover'` event but accidentally left the `element` string empty, TypePHP would evaluate the first branch (`'click'`), fail, and erroneously report: *"Argument $event['type'] must be literal 'click'"*. This false-positive blame was incredibly frustrating.
82+
83+
In v0.8.0, I completely rewrote the union validation logic with a **Discriminator-Aware Diagnostic Engine**:
84+
1. TypePHP now scans union branches for literal discriminator fields (like `'type' => 'hover'`).
85+
2. If your input matches a specific branch's discriminator, TypePHP isolates that branch and diagnoses the **exact failing field** within it.
86+
87+
```php
88+
handleEvent([
89+
'type' => 'hover',
90+
'element' => '', // Fails non-empty-string!
91+
]);
92+
93+
// Beautiful, accurate diagnostics:
94+
// Throws: TypeError: Argument $event['element'] must be of type non-empty-string, empty string ('') given
95+
```
96+
97+
And if you pass an entirely unrecognized discriminator (e.g., `'type' => 'unknown'`), TypePHP gracefully falls back to reporting the full union contract, clearly communicating that the payload matched zero valid branches.
98+
99+
**Intersection Error Formatting**
100+
Beyond unions, I've also drastically improved error message formatting for intersection types. Instead of leaking a single failing interface on shallow type mismatches, TypePHP now reports the complete intersection contract (e.g., `must be of type (Countable & Iterator)`), perfectly matching PHP 8.1+ native behavior while preserving deep property errors for intersected shapes.
101+
102+
---
103+
104+
## 3. Conditional Parameters (`$mode is 'json' ? array : string`)
105+
106+
TypePHP already supported conditional return types. In v0.8.0, I am bringing that same dynamic evaluation engine to **function and method parameters**.
107+
108+
You can now enforce that a parameter's expected type strictly depends on the runtime value of an earlier parameter, or on an inferred generic template `T`:
109+
110+
```php
111+
/**
112+
* @param 'json'|'xml' $format
113+
* @param ($format is 'json' ? array<string, mixed> : string) $payload
114+
*/
115+
function sendPayload(string $format, mixed $payload): void { ... }
116+
117+
// Evaluates $payload contract as array<string, mixed>
118+
sendPayload('json', ['status' => 'ok']);
119+
120+
// Invalid: The format is 'json', so payload MUST be an array!
121+
sendPayload('json', '<xml></xml>');
122+
// Throws: TypeError: sendPayload(): Argument $payload must be of type array, string '<xml></xml>' given
123+
```
124+
125+
This feature fully supports nested multi-branch conditionals, negated conditions (`is not`), boolean flags, and PHP 8.0+ named arguments passed in swapped order.
126+
127+
---
128+
129+
## 4. Deep Property Chain Integrity (4+ Levels Deep)
130+
131+
As developers build increasingly complex DTOs and deeply nested JSON structures, error diagnostics must remain pristine. I audited and fortified the diagnostic engine to ensure that deep property breadcrumbs remain 100% accurate, no matter how deep the chain goes.
132+
133+
```php
134+
/**
135+
* @param object{company: object{department: object{lead: object{name: non-empty-string}}}} $user
136+
*/
137+
function assignLead(object $user): void { ... }
138+
139+
// Invalid: Fails non-empty-string on the 4th level down
140+
$user->company->department->lead->name = '';
141+
142+
assignLead($user);
143+
// Throws: TypeError: assignLead(): Argument $user->company->department->lead->name must be of type non-empty-string
144+
```
145+
146+
Whether the failure is a type mismatch, a deep missing property (`...->lead is missing required property 'name'`), or a deep uninitialized PHP 8.1+ readonly property, TypePHP pinpoints the exact object and field responsible for the crash.
147+
148+
---
149+
150+
## 5. Zero-I/O Production Cache Mode
151+
152+
TypePHP operates flawlessly in CI/CD and local development, but in high-throughput production environments (like Laravel Octane or FrankenPHP), checking `@filemtime` on 1,000+ files per request to detect AST cache invalidation adds unnecessary disk I/O latency.
153+
154+
In v0.8.0, I introduced a dedicated **Production Zero-I/O Flag**.
155+
156+
```php
157+
// typephp.php
158+
return [
159+
'cache' => true,
160+
'cache_check_mtime' => false, // Maximum Production Performance
161+
];
162+
```
163+
164+
When disabled, TypePHP generates a static hash based purely on the file path, loading the cached AST instantly from memory via PHP's OPCache. No `stat()` calls. No disk checks. Pure native execution speed.
165+
166+
*(Note: When using this mode, you must run `php vendor/bin/typephp cache:rebuild` in your deployment script).*
167+
168+
---
169+
170+
## The State of the Engine: The Road to 1.0
171+
172+
With v0.8.0, the architectural foundation of TypePHP feels incredibly solid.
173+
174+
The `\WeakMap` engine successfully reifies generics with zero memory leaks. The `StreamWrapper` weaves AST checks dynamically with zero line-drift. TypePHP is natively parsing and enforcing types that traditional PHP developers could only dream of statically verifying.
175+
176+
As I look toward `v1.0.0`, my focus shifts from adding massive new architectural features to fine-tuning performance, expanding the framework integration guides (Laravel, Symfony, Shopware, Tempest), and gathering feedback from the community.
177+
178+
If you haven't tried TypePHP yet, there has never been a better time to drop it into your Pest or PHPUnit test suite:
179+
180+
```bash
181+
composer require --dev typephp/typephp
182+
vendor/bin/typephp config:init
183+
```
184+
185+
Try it out, break things, and let me know what you think on [GitHub](https://github.com/typephp-php/typephp).
186+
187+
Happy Coding!

0 commit comments

Comments
 (0)