Skip to content

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

}

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.

2 participants