Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Increase PHP 8 compatibility #2381

Merged
merged 4 commits into from
Feb 25, 2021

Conversation

bwaidelich
Copy link
Member

Related: #2233

@unlink($this->lockFlagPathAndFilename);
if (file_exists($this->lockFlagPathAndFilename)) {
@unlink($this->lockFlagPathAndFilename);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shutup operator seems to be ignored for PHP 8 - at least I got a Warning that the file didn't exist

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, see https://github.com/neos/flow-development-collection/pull/2287/checks?check_run_id=1974309752#step:12:28
PHP 8 will behave differently and I guess we need to try/catch here (our errorHandler will convert the error to an Exception) or introduce the "double shrug 🤷‍♀️🤷‍♂️()" function.
https://php.watch/versions/8.0/fatal-error-suppression

return null;
}
return $type instanceof \ReflectionNamedType ? $type->getName() : (string)$type;
return $type->isBuiltin() ? $type->getName() : null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://www.php.net/manual/en/migration80.incompatible.php#migration80.incompatible.reflection

ReflectionType::isBuiltin() method has been moved to ReflectionNamedType. ReflectionUnionType does not have it.

Not sure if the change addresses this correctly!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still need to do the instanceof check, because else we lose compatibility with PHP 7.x. Also, we did not invoke isBuiltin() here at all?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the instanceof check is in line 60 now but I'm not sure if 61 should be return (string)$type instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In PHP8 there are only ReflectionNamedType and ReflectionUnionType. Hence the question becomes: How should we handle a union of a builtin type with other types here?
For PHP >= 7.1 only ReflectionNamedType exists, so returning null should be okay. If we want to be super sure, it should be PHP < 8 ? (string)$type : null

@@ -149,7 +149,7 @@ public function dispatch(string $signalClassName, string $signalName, array $sig
}

foreach ($this->slots[$signalClassName][$signalName] as $slotInformation) {
$finalSignalArguments = $signalArguments;
$finalSignalArguments = array_values($signalArguments);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if that's the proper fix, but I got an error

named argument "$response" doesn't exist

(or similar) because PHP 8 tries to map this to a named argument if the array contains associative keys

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: WIth PHP 8.1 this won't be required any longer (https://wiki.php.net/rfc/array_unpacking_string_keys)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but will be some time until we have PHP >= 8.1 minimum :)

if ($type === T_STRING) {
$namespaceParts[] = $value;
if ($type === T_STRING || $type === T_NAME_FULLY_QUALIFIED || $type === T_NAME_QUALIFIED) {
$namespaceParts[] = ltrim($value, '\\');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently the behavior of token_get_all() has changed..

@albe
Copy link
Member

albe commented Jan 27, 2021

See #2287 - you could add your changes there and would immediately get feedback from the running PHP 8 builds

@albe albe changed the base branch from master to albe-doctrine-php8 February 25, 2021 07:29
@albe albe merged commit 8ec85f3 into albe-doctrine-php8 Feb 25, 2021
@albe albe deleted the feature/2233-php-8-compatibilty branch February 25, 2021 08:00
@albe
Copy link
Member

albe commented Feb 25, 2021

FYI: I merged these changes into #2287 prefering yours - so we can close this and continue on the other PR with getting us PHP8 ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants