@@ -181,6 +181,31 @@ PHP 8.6 UPGRADE NOTES
181181========================================
182182
183183- Core:
184+ . Added support for runtime-bound-checked generics. Classes, interfaces,
185+ traits, functions, methods, closures, and arrow functions can now declare
186+ type parameters with optional bounds (`T : Foo`), defaults (`T = int`),
187+ and variance markers (`+T`, `-T`):
188+
189+ class Box<T : object> {
190+ public T $value;
191+ public function get(): T { return $this->value; }
192+ }
193+
194+ function id<T>(T $x): T { return $x; }
195+
196+ Call sites accept turbofish type arguments (`Box::<int>::new()`,
197+ `id::<int>(7)`); use sites accept type arguments on named types
198+ (`Box<int>`, `array<int, string>`, `iterable<T>`, `self<T>`,
199+ `static<T>`, `parent<T>`). Recursive bounds (`T : Comparable<T>`)
200+ are supported. Anonymous classes cannot declare type parameters.
201+
202+ At runtime each type parameter is replaced by its declared bound
203+ (or `mixed` when unbounded, or when the bound is invalid in the
204+ target position, e.g. `callable` on a property), and type
205+ arguments are discarded. Pre-erasure metadata is preserved on
206+ functions, methods, and class entries and is exposed through
207+ Reflection so that PHP-based static-analysis tools can consume
208+ generics without re-parsing source.
184209 . It is now possible to use reference assign on WeakMap without the key
185210 needing to be present beforehand.
186211 . It is now possible to define the `__debugInfo()` magic method on enums.
@@ -323,6 +348,23 @@ PHP 8.6 UPGRADE NOTES
323348 RFC: https://wiki.php.net/rfc/isreadable-iswriteable
324349 . Added ReflectionParameter::getDocComment().
325350 RFC: https://wiki.php.net/rfc/parameter-doccomments
351+ . Added ReflectionFunctionAbstract::isGeneric() and
352+ ReflectionFunctionAbstract::getGenericParameters() (covers
353+ ReflectionFunction, ReflectionMethod, closures, and arrow functions).
354+ . Added ReflectionClass::isGeneric() and
355+ ReflectionClass::getGenericParameters().
356+ . Added ReflectionClass::getGenericArgumentsForParentClass(),
357+ ReflectionClass::getGenericArgumentsForParentInterface(string $name),
358+ and ReflectionClass::getGenericArgumentsForUsedTrait(string $name) for
359+ inspecting the type arguments supplied at a class's own extends /
360+ implements / use sites. Returns null when no type arguments were
361+ specified for that ancestor at this class's clause site (consumers
362+ enumerate ancestors via the existing getParentClass() / getInterfaces()
363+ / getTraits() APIs).
364+ . Added ReflectionNamedType::hasGenericArguments() and
365+ ReflectionNamedType::getGenericArguments(). The arguments are returned
366+ as ReflectionType instances in source order (pre-erasure form);
367+ ReflectionNamedType::getName() continues to return the erased name.
326368
327369- Intl:
328370 . `grapheme_strrev()` returns strrev for grapheme cluster unit.
@@ -354,6 +396,15 @@ PHP 8.6 UPGRADE NOTES
354396 RFC: https://wiki.php.net/rfc/tls_session_resumption
355397 . Openssl\Psk
356398
399+ - Reflection:
400+ . ReflectionGenericTypeParameter (final, instances obtained via
401+ ReflectionClass::getGenericParameters() and
402+ ReflectionFunctionAbstract::getGenericParameters()).
403+ . ReflectionTypeParameterReference (extends ReflectionType, appears only
404+ inside pre-erasure type expressions: bounds, defaults, and the elements
405+ of ReflectionNamedType::getGenericArguments()).
406+ . enum ReflectionGenericVariance { Invariant; Covariant; Contravariant }.
407+
357408- Standard:
358409 . enum SortDirection
359410 RFC: https://wiki.php.net/rfc/sort_direction_enum
0 commit comments