-
Notifications
You must be signed in to change notification settings - Fork 5
Use PHP 8.0 union types #89
Copy link
Copy link
Closed
Labels
subject/typingIssues related to the type systemIssues related to the type systemtype/enhancementNew feature or requestNew feature or requesttype/refactoringA refactoring that should be applied to make the code easier to understandA refactoring that should be applied to make the code easier to understand
Milestone
Metadata
Metadata
Assignees
Labels
subject/typingIssues related to the type systemIssues related to the type systemtype/enhancementNew feature or requestNew feature or requesttype/refactoringA refactoring that should be applied to make the code easier to understandA refactoring that should be applied to make the code easier to understand
PHP 8.0 introduces the concept of union types, which allows us to explicitly type a function with multiple different types. php-cypher-dsl currently polyfills this feature through the
ErrorTraittrait. However, there are a few problems with this polyfill approach:Therefore, I want to propose to drop support for PHP 7.4 and start using PHP 8.0 union types. Implementing this is relatively straightforward:
ErrorTraittrait.The
ErrorTraittrait also has a method for checking whether the type of each value in an array is allowed. This is currently not supported through PHP's type system. There are two options to fix this:arraytype in signatures, orI think the first option is best. Type checking of arrays is only used in a few places (five times throughout the entire library), and it adds complexity and overhead. Most usages can also be replaced by typed variadic parameters.