Skip to content
This repository was archived by the owner on Jul 14, 2023. It is now read-only.

Add the Generic.PHP.BacktickOperator rule #28

Merged
merged 2 commits into from
Apr 19, 2022

Conversation

aadmathijssen
Copy link
Member

This PR disallows the use of the backtick operator by adding the Generic.PHP.BacktickOperator rule.

Consider the following confusing PHP code:

<?php

declare(strict_types=1);

echo '`ls`';
echo `'ls'`;

With the current ruleset, this does not report any error.

After merging this PR, the following error is reported:

FILE: /path/to/file.php
--------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 1 LINE
--------------------------------------------------------------------------------------------
 6 | ERROR | Use of the backtick operator is forbidden
   |       | (Generic.PHP.BacktickOperator.Found)
 6 | ERROR | Use of the backtick operator is forbidden
   |       | (Generic.PHP.BacktickOperator.Found)
--------------------------------------------------------------------------------------------

To repair this error, you can use the shell_exec function instead, that does not require a potentially confusing syntax:

<?php

declare(strict_types=1);

echo '`ls`';
echo shell_exec('ls');

This disallows the use of the backtick operator.
@aadmathijssen aadmathijssen force-pushed the feature/add-generic-php-backtickoperator-sniff branch from 33d75c6 to d5ecc35 Compare March 15, 2022 10:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants