backtick_to_shell_exec.rst 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. ===============================
  2. Rule ``backtick_to_shell_exec``
  3. ===============================
  4. Converts backtick operators to ``shell_exec`` calls.
  5. Description
  6. -----------
  7. Conversion is done only when it is non risky, so when special chars like
  8. single-quotes, double-quotes and backticks are not used inside the command.
  9. Examples
  10. --------
  11. Example #1
  12. ~~~~~~~~~~
  13. .. code-block:: diff
  14. --- Original
  15. +++ New
  16. <?php
  17. -$plain = `ls -lah`;
  18. -$withVar = `ls -lah $var1 ${var2} {$var3} {$var4[0]} {$var5->call()}`;
  19. +$plain = shell_exec("ls -lah");
  20. +$withVar = shell_exec("ls -lah $var1 ${var2} {$var3} {$var4[0]} {$var5->call()}");
  21. Rule sets
  22. ---------
  23. The rule is part of the following rule sets:
  24. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  25. - `@Symfony <./../../ruleSets/Symfony.rst>`_
  26. References
  27. ----------
  28. - Fixer class: `PhpCsFixer\\Fixer\\Alias\\BacktickToShellExecFixer <./../../../src/Fixer/Alias/BacktickToShellExecFixer.php>`_
  29. - Test class: `PhpCsFixer\\Tests\\Fixer\\Alias\\BacktickToShellExecFixerTest <./../../../tests/Fixer/Alias/BacktickToShellExecFixerTest.php>`_
  30. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.