PHP 8.0 type improvements
Blog post from Upsun
PHP 8 introduces significant enhancements to its type system, notably with the introduction of union types, which allow parameters, return types, and properties to accept multiple types, such as string|array. This update enables clearer and more flexible API documentation and usage, allowing for more complex and precise type definitions that were previously difficult to document. Additionally, PHP 8 introduces the Stringable interface, enhancing the usability of the __toString() method in strict typing scenarios, thus allowing objects implementing this method to be type-checked as stringable. The release also includes the mixed type, which explicitly allows any type, providing clearer intent in code, and introduces a static return type for methods, beneficial for interfaces with chained methods. These improvements, alongside other minor enhancements like the magic constant for class names, aim to provide better performance and developer experience in one of the most popular server-side languages.