Split off from #10219
Upgrade all the support modules to support php 8.1
Agreed way forward to resolve common errors #10237 (comment)
Reference to some breaking changes in php 8.1 - https://stitcher.io/blog/new-in-php-81#breaking-changes
Note
Steve created some science experiment to add a _a method that can note docblock/parameter type mismatched and a _c method that can recast variable to their expected type. He also has a script to apply it to the entire code base.
Update: this approach won't work for php 8.1. Reason being that the _a() method profiling will certainly detect the say all the string and null arguments being passed in for a param, we cannot determine whether or not null is valid in this instance or not, so we don't know if _c('string', $myvar, 1) should be included or not
Acceptance criteria
Explanation of the conversion process in the PRs below
- Automatic code modification using https://github.com/emteknetnz/php81-fixer
- Static code analysis that ensures any arguments passed to native php functions are not null
- If the native param only accepts a single type of (string|bool|int|float) then it is cast i.e (string)
- If the native param only accepts an array then it uses the ternary operator i.e. ?: []
- If the native param accepts multiple types then it uses the ternary operator with a bias to using string i.e. ?: ''
- Use the null coalescing operator for variables passed to native functions that do not accept null values
- There are some conditions where arguments are not converted such as the argument is a native constant, is an inner native function call with a single return type, is using the
class static property e.g. SiteTree::class
Because this is an automated process this certainly goes on the side of over converting code. If we move to full-type hinting param and return type in the future, we could run another code sweep to remove a bunch of the code conversions. Currently we cannot rely on the docblock types as they are very unreliable.
There are also #[\ReturnTypeWIllChange] method attributes added to class methods where relevant, as well as some other methods that are updated, such as adding __serialized()/__unserialized()
Current PHP 8.1 unit test status
Follow up PRs
PRs
GraphQL 3 PRs
"Manual fix" PRs
solr-php-client fork
Installer (all prs use null coalesce)
No changes
- silverstripe/silverstripe-errorpage
- silverstripe/silverstripe-siteconfig
Kitchen-sink (all prs use null coalesce)
No changes
- content-widget
- crontask
- elemental-fileblock
- security-extensions
- taxonomy
- dnadesign/silverstripe-elemental-userforms
- tractorcow/silverstripe-proxy-db
PRs for dependencies
Split off from #10219
Upgrade all the support modules to support php 8.1
Agreed way forward to resolve common errors #10237 (comment)
Reference to some breaking changes in php 8.1 - https://stitcher.io/blog/new-in-php-81#breaking-changes
Note
Steve created some science experiment to add a_amethod that can note docblock/parameter type mismatched and a_cmethod that can recast variable to their expected type. He also has a script to apply it to the entire code base.Update: this approach won't work for php 8.1. Reason being that the _a() method profiling will certainly detect the say all the
stringandnullarguments being passed in for a param, we cannot determine whether or notnullis valid in this instance or not, so we don't know if_c('string', $myvar, 1)should be included or notAcceptance criteria
Explanation of the conversion process in the PRs below
- If the native param only accepts a single type of(string|bool|int|float)then it is cast i.e(string)- If the native param only accepts anarraythen it uses the ternary operator i.e.?: []- If the native param accepts multiple types then it uses the ternary operator with a bias to using string i.e.?: ''classstatic property e.g.SiteTree::classBecause this is an automated process this certainly goes on the side of over converting code. If we move to full-type hinting param and return type in the future, we could run another code sweep to remove a bunch of the code conversions. Currently we cannot rely on the docblock types as they are very unreliable.
There are also
#[\ReturnTypeWIllChange]method attributes added to class methods where relevant, as well as some other methods that are updated, such as adding__serialized()/__unserialized()Current PHP 8.1 unit test status
Follow up PRs
PRs
GraphQL 3 PRs
"Manual fix" PRs
solr-php-client fork
Installer (all prs use null coalesce)
No changes
Kitchen-sink (all prs use null coalesce)
No changes
PRs for dependencies
Add method attribute for PHP 8.1 compatibility PTCInc/solr-php-client#8^ if this isn't merged, then we should look to copy into thirdparty folder << update have moved to thirdparty folder in fulltextsearch module