@@ -177,6 +177,31 @@ PHP 8.6 UPGRADE NOTES
177177========================================
178178
179179- Core:
180+ . Added support for runtime-bound-checked generics. Classes, interfaces,
181+ traits, functions, methods, closures, and arrow functions can now declare
182+ type parameters with optional bounds (`T : Foo`), defaults (`T = int`),
183+ and variance markers (`+T`, `-T`):
184+
185+ class Box<T : object> {
186+ public T $value;
187+ public function get(): T { return $this->value; }
188+ }
189+
190+ function id<T>(T $x): T { return $x; }
191+
192+ Call sites accept turbofish type arguments (`Box::<int>::new()`,
193+ `id::<int>(7)`); use sites accept type arguments on named types
194+ (`Box<int>`, `array<int, string>`, `iterable<T>`, `self<T>`,
195+ `static<T>`, `parent<T>`). Recursive bounds (`T : Comparable<T>`)
196+ are supported. Anonymous classes cannot declare type parameters.
197+
198+ At runtime each type parameter is replaced by its declared bound
199+ (or `mixed` when unbounded, or when the bound is invalid in the
200+ target position, e.g. `callable` on a property), and type
201+ arguments are discarded. Pre-erasure metadata is preserved on
202+ functions, methods, and class entries and is exposed through
203+ Reflection so that PHP-based static-analysis tools can consume
204+ generics without re-parsing source.
180205 . It is now possible to use reference assign on WeakMap without the key
181206 needing to be present beforehand.
182207 . It is now possible to define the `__debugInfo()` magic method on enums.
@@ -311,6 +336,23 @@ PHP 8.6 UPGRADE NOTES
311336 RFC: https://wiki.php.net/rfc/isreadable-iswriteable
312337 . Added ReflectionParameter::getDocComment().
313338 RFC: https://wiki.php.net/rfc/parameter-doccomments
339+ . Added ReflectionFunctionAbstract::isGeneric() and
340+ ReflectionFunctionAbstract::getGenericParameters() (covers
341+ ReflectionFunction, ReflectionMethod, closures, and arrow functions).
342+ . Added ReflectionClass::isGeneric() and
343+ ReflectionClass::getGenericParameters().
344+ . Added ReflectionClass::getGenericArgumentsForParentClass(),
345+ ReflectionClass::getGenericArgumentsForParentInterface(string $name),
346+ and ReflectionClass::getGenericArgumentsForUsedTrait(string $name) for
347+ inspecting the type arguments supplied at a class's own extends /
348+ implements / use sites. Returns null when no type arguments were
349+ specified for that ancestor at this class's clause site (consumers
350+ enumerate ancestors via the existing getParentClass() / getInterfaces()
351+ / getTraits() APIs).
352+ . Added ReflectionNamedType::hasGenericArguments() and
353+ ReflectionNamedType::getGenericArguments(). The arguments are returned
354+ as ReflectionType instances in source order (pre-erasure form);
355+ ReflectionNamedType::getName() continues to return the erased name.
314356
315357- Intl:
316358 . `grapheme_strrev()` returns strrev for grapheme cluster unit.
@@ -342,6 +384,15 @@ PHP 8.6 UPGRADE NOTES
342384 RFC: https://wiki.php.net/rfc/tls_session_resumption
343385 . Openssl\Psk
344386
387+ - Reflection:
388+ . ReflectionGenericTypeParameter (final, instances obtained via
389+ ReflectionClass::getGenericParameters() and
390+ ReflectionFunctionAbstract::getGenericParameters()).
391+ . ReflectionTypeParameterReference (extends ReflectionType, appears only
392+ inside pre-erasure type expressions: bounds, defaults, and the elements
393+ of ReflectionNamedType::getGenericArguments()).
394+ . enum ReflectionGenericVariance { Invariant; Covariant; Contravariant }.
395+
345396- Standard:
346397 . enum SortDirection
347398 RFC: https://wiki.php.net/rfc/sort_direction_enum
0 commit comments