1.2.1346. Use PHP7 Encapsed Strings¶
PHP 7 has optimized the handling of double-quoted strings. In particular, double-quoted strings are much less memory hungry than classic concatenations.
PHP allocates memory at the end of the double-quoted string, making only one call to the allocator. On the other hand, concatenations are allocated each time they include dynamic content, leading to higher memory consumption. Concatenations are still needed with constants, static constants, magic constants, functions, static properties or static methods.
<?php
$bar = 'bar';
/* PHP 7 optimized this */
$a = "foo and $bar";
/* This is PHP 5 code (aka, don't use it) */
$a = 'foo and ' . $bar;
// Constants can't be used with double quotes
$a = 'foo and ' . __DIR__;
$a = "foo and __DIR__"; // __DIR__ is not interpolated
?>
See also PHP 7 performance improvements (3/5): Encapsed strings optimization.
1.2.1346.1. Connex PHP features¶
1.2.1346.1.1. Specs¶
Short name |
Performances/PHP7EncapsedStrings |
Rulesets |
|
Exakat since |
1.0.4 |
PHP Version |
All |
Severity |
|
Time To Fix |
|
Precision |
Very high |
Available in |