Innovate faster and cut risk with PHP experts from Zend Services.
Explore Services
See How Zend Helps Leading Hosting Providers Keep Their Managed Sites on Secure PHP
Read More
Learn PHP from PHP experts with free, on-demand, and instructor led courses.
Explore Training
Submit support requests and browse self-service resources.
Explore Support
PHPCompatibility.Operators.ChangedConcatOperatorPrecedence.Found
Manually add parentheses where appropriate.
$response = '1234567890'; $header = 'Content-length: ' . strlen($response) + 1; header($header);
In PHP 5.6, $header would contain 1. In PHP 7.0 to 7.4, it would contain the same, but will also emit a deprecation warning. In PHP 8.0+, it will contain Content-length: 11.
$header
1
Content-length: 11
The original behavior is most likely faulty. We can guess that the dev meant to send the Content-length: 11 header, but in reality, the dev was sending 1. This is because the original code concatenated first, producing 0. Therefore, 0 + 1 = 1.
0
0 + 1 = 1
The straightforward solution is to systematically add parentheses around the + or - expressions that were flagged by PHPCompatibility. In most cases, it would fix a bug previously unknown to the customer, but in rare cases it can also introduce new bugs. Thorough testing is needed.
+
-
$response = '1234567890'; header('Content-length: ' . strlen($response) + 1);
We wrap the arithmetic expression in parentheses, so that to get the correct number is concatenated:
$response = '1234567890'; header('Content-length: ' . (strlen($response) + 1));
Although this fixes the warning, it could potentially change the behavior and have an impact later during execution, so it's important to thoroughly test the impact of these changes.
Increase security and cut risk by simplifying PHP application upgrades and migrations.
Long Term Support buys organizations time to migrate.