:sparkles: PHP 8.2 | New `PHPCompatibility.TextStrings.RemovedDollarBraceStringEmbeds` sniff by jrfnl · Pull Request #1424 · PHPCompatibility/PHPCompatibility
…gEmbeds` sniff
PHP 8.2 will be deprecating two out of the four ways to embed variables and expressions in text strings (heredocs and double quoted strings).
> PHP allows embedding variables in strings with double-quotes (") and heredoc in various ways.
> 1. Directly embedding variables (“$foo”)
> 2. Braces outside the variable (“{$foo}”)
> 3. Braces after the dollar sign (“${foo}”)
> 4. Variable variables (“${expr}”, equivalent to (string) ${expr})
>
> Options 1 and 2 have their pros and cons. Options 3 and 4 are easily confused due to overlapping syntax, 3 is strictly less capable than 1 and 2, and 4 has completely different semantics (variable variables) that are rarely useful in string interpolation.
>
> This RFC proposes to deprecate options 3 and 4 in PHP 8.2 and remove them in PHP 9.0.
This commit introduces a new sniff to detect this deprecation.
Analyzing code for this deprecation was affected by a bug in the PHPCS Tokenizer discovered while writing this sniff. As of PHPCSUtils 1.0.0-alpha4, the utility methods in PHPCSUtils include a work-around for this bug and are stable for our purposes.
Also note that while the included unit tests should absolutely be sufficient for our purposes, the PHPCSUtils methods used to retrieve embedded variables and expressions are tested **_in-depth_** (> 1000 tests for that functionality alone), so we should be good ;-)
Last note: the tests are split in two files as any code after a PHP 7.3 heredoc/nowdoc will not tokenize correctly on PHP < 7.3. Splitting the tests into two files works as a work-around for that.
Includes unit tests.
Includes sniff documentation.
Refs:
* https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation
* php/php-src 8212
* https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing
* https://gist.github.com/iluuu1994/72e2154fc4150f2258316b0255b698f2
* squizlabs/PHP_CodeSniffer 3604
jrfnl
mentioned this pull request
18 tasks
wimg approved these changes Dec 5, 2022
wimg
deleted the
php-8.2/new-removeddollarbraceembeds-sniff
branch
jrfnl
mentioned this pull request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters