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

TASK: Add basic support for PHP8 #2287

Merged
merged 34 commits into from
Mar 22, 2021
Merged

TASK: Add basic support for PHP8 #2287

merged 34 commits into from
Mar 22, 2021

Conversation

albe
Copy link
Member

@albe albe commented Nov 28, 2020

This makes our code base work on PHP 8. It does not yet add support for PHP 8 features. See #2404 for this.

Related to #2233

@albe
Copy link
Member Author

albe commented Nov 28, 2020

This depends on doctrine/migrations#980 now

@bwaidelich bwaidelich marked this pull request as draft December 9, 2020 09:56
@bwaidelich
Copy link
Member

FYI: I converted this PR to a draft so that it doesn't get merged by accident (=> see doctrine/migrations#980)

@albe
Copy link
Member Author

albe commented Dec 23, 2020

The blocker has been solved by the doctrine team for christmas, even for 2.3.x versions :) see doctrine/migrations#1102

But...

Cloning into 'Packages/Framework'...
fatal: reference repository '/home/travis/.cache/composer/vcs/-home-travis-
build-neos-flow-development-collection/' is shallow

❓ ❔ ❓ WTF Travis?

@albe
Copy link
Member Author

albe commented Dec 23, 2020

0.16s$ composer config --json repositories.flow.options '{"symlink": false}'

[RuntimeException]
Failed to update composer.json with a valid format, reverting to the origin
al content. Please report an issue to us with details (command you run and
a copy of your composer.json).

[Composer\Json\JsonValidationException]
"./composer.json" does not match the expected JSON schema

Oh boi... 🤷‍♂️

@albe
Copy link
Member Author

albe commented Dec 23, 2020

Holy cow - there you go ✔️🎁

@albe albe changed the base branch from master to 7.0 December 23, 2020 21:16
@albe albe marked this pull request as ready for review December 23, 2020 21:16
@albe albe requested review from kdambekalns and bwaidelich and removed request for kdambekalns and bwaidelich December 23, 2020 21:16
@albe
Copy link
Member Author

albe commented Dec 23, 2020

Oops, the PHP 8 tests actually fail - they just were allowed to fail because they were still "nightly" 🙈

@albe
Copy link
Member Author

albe commented Jan 3, 2021

Intermediary result: Errors: 18, Failures: 16 -> Errors: 7, Failures: 7

@albe albe marked this pull request as draft January 4, 2021 22:58
@albe albe force-pushed the albe-doctrine-php8 branch from 3c93473 to e083f68 Compare February 24, 2021 21:12
Copy link
Member Author

@albe albe left a comment

Choose a reason for hiding this comment

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

Added some comments for easier review

@@ -589,7 +589,7 @@ public function requireOnceDoesNotSwallowPhpNoticesOfTheIncludedFile()
$backend->setCache($mockCache);

$entryIdentifier = 'SomePhpEntryWithPhpNotice';
$backend->set($entryIdentifier, '<?php $undefined ++; ?>');
Copy link
Member Author

Choose a reason for hiding this comment

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

This is no longer a E_NOTICE in PHP8

@@ -405,7 +405,7 @@ public function requireOnceDoesNotSwallowPhpWarningsOfTheIncludedFile()
$entryIdentifier = 'SomePhpEntryWithPhpWarning';

$simpleFileBackend = $this->getSimpleFileBackend();
$simpleFileBackend->set($entryIdentifier, '<?php trigger_error("Warning!", E_WARNING); ?>');
$simpleFileBackend->set($entryIdentifier, '<?php trigger_error("Warning!", E_USER_WARNING); ?>');
Copy link
Member Author

Choose a reason for hiding this comment

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

Only E_USER_X can be manually triggered. PHP 7 was lenient with this though.

*/
public function getDeclaredReturnType()
{
if (!is_callable([$this, 'getReturnType'])) {
return null;
}
$type = $this->getReturnType();
return $type !== null ? (string)$type : null;
return $type !== null ? ltrim((string)$type, '?') : 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.

PHP8 returns the nullable type operator

*/
public function getBuiltinType()
{
$type = $this->getType();
if ($type === null || !$type->isBuiltin()) {
if (!$type instanceof \ReflectionNamedType) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Could be a ReflectionUnionType in PHP 8

@@ -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.

PHP8 named parameters...

// We use parameter type here to make class_alias usage work and return the hinted class name instead of the alias
$parameterInformation[self::DATA_PARAMETER_CLASS] = $parameterType;
} elseif ($parameterType === 'array') {
Copy link
Member Author

Choose a reason for hiding this comment

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

Else here makes sure that array is not marked as DATA_PARAMETER_SCALAR_DECLARATION

if ($type === T_STRING) {
$namespaceParts[] = $value;
$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.

Not 100% sure any more this is required, because in PHP8 namespace is parsed with above tokens. But we always expect namespaces to not start with \ and this guarantees it.

@@ -422,14 +422,14 @@ public function round($subject, $precision = 0)
*/
public function sign($x)
{
if ($x < 0) {
if (!is_numeric($x)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

In PHP8 'foo' compares differently to a number: see https://3v4l.org/Zhdsh
It is more sane to first check the non-numeric case and return NAN anyway, as it is done similarly in other math helper functions.

Neos.Cache/Classes/Backend/FileBackend.php Outdated Show resolved Hide resolved
@albe
Copy link
Member Author

albe commented Mar 14, 2021

Now only Behat fails...

Created database schema.
...............---..........................................
--- Failed hooks:

BeforeScenario @fixtures # FeatureContext::resetTestFixtures()
  There is no active transaction (PDOException)

Likely related to doctrine/migrations#1104

Edit: Fixed with neos/behat@f68dea2 and all green ✔️ - the exception basically just states that the transaction around the migration was already committed. BUT that is only a broken fix, because effectively migrations will stop at the first migration containing DDL. The right solution would be to catch and ignore the exception around every single migration, which we can not do and needs to be done by doctrine/migrations. The other alternative is to change all existing mysql Migrations to include isTransactional() { return false; }
See also doctrine/migrations#1104 (comment)

Will be resolved once doctrine/migrations#1131 is released. It's merged into 2.3.x-dev already, so won't take too long I guess. I would still keep the odd semi-fix of neos/behat@f68dea2, just in case.

Copy link
Member

@bwaidelich bwaidelich left a comment

Choose a reason for hiding this comment

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

Nice one, thanks for taking care.
+1 (by reading). Just a question/suggestion re "double-shrug" comments :)

Neos.Cache/Classes/Backend/FileBackend.php Outdated Show resolved Hide resolved
Neos.Cache/Classes/Backend/FileBackend.php Outdated Show resolved Hide resolved
Neos.Flow/Classes/Core/LockManager.php Outdated Show resolved Hide resolved
Neos.Flow/Classes/Core/LockManager.php Outdated Show resolved Hide resolved
Neos.Flow/Classes/Package/PackageManager.php Outdated Show resolved Hide resolved
Neos.Utility.Files/Classes/Files.php Outdated Show resolved Hide resolved
@albe
Copy link
Member Author

albe commented Mar 21, 2021

https://twitter.com/paxuclus/status/1373351604930412547 - still need a second approval :)

Copy link
Member

@kdambekalns kdambekalns left a comment

Choose a reason for hiding this comment

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

👏 Some minor tweaks, please.

@albe
Copy link
Member Author

albe commented Mar 22, 2021

Thanks @kdambekalns ! All valid feedback and applied :)

Copy link
Member

@kdambekalns kdambekalns left a comment

Choose a reason for hiding this comment

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

❤️

@albe
Copy link
Member Author

albe commented Mar 22, 2021

👿 were are those unrelated test failures coming from now? 😫

@kdambekalns
Copy link
Member

👿 were are those unrelated test failures coming from now? 😫

Maybe they are not enitrely unrelated? Could be from 23f4bc3#diff-7d0a1ee9681327fd82562aa2d7fcd5ed3b083a2283085f8c760eb4fab0e8c73aR1808, no?

@albe
Copy link
Member Author

albe commented Mar 22, 2021

👿 were are those unrelated test failures coming from now? 😫

Maybe they are not enitrely unrelated? Could be from 23f4bc3#diff-7d0a1ee9681327fd82562aa2d7fcd5ed3b083a2283085f8c760eb4fab0e8c73aR1808, no?

🤔 ...

@albe
Copy link
Member Author

albe commented Mar 22, 2021

There you go :)

@albe albe merged commit 1f88b67 into 7.0 Mar 22, 2021
@albe albe deleted the albe-doctrine-php8 branch March 22, 2021 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants