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

Fix PHP 8.1 deprecations #1016

Merged
merged 1 commit into from
Nov 22, 2021
Merged

Fix PHP 8.1 deprecations #1016

merged 1 commit into from
Nov 22, 2021

Conversation

derrabus
Copy link
Member

This PR fixes two pieces of code that trigger a deprecation error on PHP 8.1. You can see them in the CI output of #1012.

@derrabus derrabus added the Bug Bug Fix label Nov 20, 2021
@@ -714,7 +714,7 @@ private function updateContents(string $newContents, array $newData, int $newPos
private function convertToYaml($data)
{
$indent = $this->depth > 0 && isset($this->indentationForDepths[$this->depth])
? $this->indentationForDepths[$this->depth] / $this->depth
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 division might evaluate to a float value. The problem is that $indent is implicitly cast to an integer later and PHP 8.1 will complain if that implicit cast would result in a loss of precision. Since the loss in precision is actually desired here, I'm performing an integer division instead which will always yield an integer.

@@ -1132,7 +1132,7 @@ private function removeMetadataKeys(array $data)
unset($data[$key]);
}

if (0 === strpos($val, self::COMMENT_PLACEHOLDER_VALUE)) {
if (null !== $val && 0 === strpos($val, self::COMMENT_PLACEHOLDER_VALUE)) {
Copy link
Member Author

@derrabus derrabus Nov 20, 2021

Choose a reason for hiding this comment

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

💡 Passing null to strpos() will trigger a deprecation on PHP 8.1.

@weaverryan
Copy link
Member

Thank you @derrabus!

@weaverryan weaverryan merged commit 0938791 into symfony:main Nov 22, 2021
@weaverryan weaverryan mentioned this pull request Nov 22, 2021
@derrabus derrabus deleted the bugfix/php-8.1-deprecations branch November 22, 2021 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants