Skip to content
Snippets Groups Projects
Commit 151eff0f authored by Stefan Bürk's avatar Stefan Bürk
Browse files

[BUGFIX] Avoid return type deprecation with PHP8.3 in TreeNodeCollection

PHP8.3 changed return type for `\ArrayObject::asort()`
from `bool` to `true` and will trigger a `E_DEPRECATED`
notice since PHP8.3 for extending classes with
incompatible signature. Regarding the documentation the return
type changed in PHP8.2.0 already.

It's not really clear why this has not been detected
earlier. The documentation [1] states that this should
have changed with PHP 8.2.0. However, the PHP 8.2 based
testing we have in place did not pick that up yet.

Further investigation show, that the corresponding
change on the PHP source repository is only available
on master and for the `PHP8.3.0alpha1` tag [2][3]. With
that change the stub file and the argument information
header file for this and other methods changed.

The PHP source change targets more return types, but
we did not hit yet others then the one case detected
through unit tests.

The return type can be only be changed when PHP8.3+ is the
minimum php version. Therefore, we add the known attribute
`#[\ReturnTypeWillChange]` to the method along with a
a comment to change this when requirements are fullfilled.

TYPO3 11.5 already have this attribute, so this issue
occurs only with TYPO3 v12 and main. Reason for this
is the fact, that with #98035 that attribute has been
resolved by using compatible return types at that moment.

This can be checked by executing unit tests with PHP8.3
with and without this change.

Use-full command:

> Build/Scripts/runTests.sh -p 8.3 -s unit

[1] https://www.php.net/manual/en/arrayobject.asort.php#refsect1-arrayobject.asort-changelog
[2] https://github.com/php/php-src/commit/85338569debd3f669ef5bc793822b2d9f3f1b1ea
[3] https://github.com/php/php-src/pull/11200

Resolves: #100992
Related: #98035
Releases: main, 12.4
Change-Id: Ic3b8cacdcf387a2d23eaeaf66222de6078d54f2d
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/79251


Reviewed-by: default avatarElias Häußler <e.haeussler@familie-redlich.de>
Tested-by: default avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: default avatarOliver Klee <typo3-coding@oliverklee.de>
Tested-by: default avatarElias Häußler <e.haeussler@familie-redlich.de>
Tested-by: default avatarBenni Mack <benni@typo3.org>
Reviewed-by: default avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Reviewed-by: default avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: default avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: default avatarcore-ci <typo3@b13.com>
parent 66d26a96
Branches
Tags
No related merge requests found
......@@ -43,8 +43,11 @@ class TreeNodeCollection extends \ArrayObject
* Sorts the internal nodes array
*
* @param int $flags Optional parameter, ignored. Added to be compatible with asort method signature in PHP 8.
*
* @todo Use return type "true" instead of bool if PHP8.3+ is minimum supported and remove #[\ReturnTypeWillChange].
*/
public function asort($flags = SORT_REGULAR): bool
#[\ReturnTypeWillChange]
public function asort(int $flags = SORT_REGULAR): bool
{
$this->uasort([$this, 'nodeCompare']);
return true;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment