You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit de29fb8
Browse filesBrowse the repository at this point in the historyBrowse files
***PHP 8.0+ native union syntax:**`int|null $id = null` or `array|null $options = null`
45
+
46
+
### The Inherent Syntax Limitation in Native PHP
47
+
48
+
PHP's native type system cannot express inner collection or refinement types in method signatures. You cannot natively write `?string[] $tags = null` or `?positive-int $id = null` in PHP.
49
+
50
+
Because of this language limitation, developers in major enterprise libraries (including **Symfony**, **Laravel**, and **Doctrine**) universally follow this convention:
51
+
1. They declare the **outer nullability** natively in PHP: `?array $groups = null`
52
+
2. They use the **DocBlock strictly to describe the inner elements**: `/** @param string[] $groups */`
If your project requires 100% strict DocBlock auditing where DocBlocks are treated as the absolute literal law, set `'respect_native_nullability' => false` in `typephp.php`:
93
+
94
+
```php
95
+
// typephp.php
96
+
return [
97
+
'respect_native_nullability' => false,
98
+
];
99
+
```
100
+
101
+
In strict mode, if a native parameter is `?array $tags = null` but the DocBlock says `@param string[] $tags` (omitting `|null`), passing `null` will be strictly rejected with a `TypeError`.
Modern PHP packages and frameworks (such as **Doctrine Collections**, **Symfony**, and **Laravel**) frequently declare both broad IDE-fallback annotations and strict static analysis contracts on the exact same method signature:
0 commit comments