This is an old revision of the document!
PHP RFC: Deprecate Backtick Operator (V2)
- Version: 0.1
- Date: 2019-10-04
- Author: Mark Randall, email@example.com
- Status: Draft
- First Published at:https://wiki.php.net/rfc/deprecate-backtick-operator-v2
- Target: 8.0
PHP contains multiple functions for executing system commands from within a PHP script as detailed in the “Program execution functions” section of the manual (https://www.php.net/manual/en/book.exec.php). However, there is another method that is less known, and which is not immediately obvious in its intent when viewed in source code.
The backtick operator, also known as the execution operator, runs the contents within it as a shell command.
The backtick operator is identical to shell_exec, but does so in a manner that is significantly less intuitive as to its purpose. This RFC is written based on the author's belief that the existence of backticks (as opposed to the named function) should be considered to represent unnecessary cognitive overhead while learning and using the language, while offering little unique benefit to offset this cost.
This RFC proposes that the use of the backtick operator emits a E_DEPRECATED warning in PHP 8.0, noting the use of shell_exec and its related family of functions to achieve the same goals. This proposal does not suggest that the backtick operator should be removed with the intent of using it for other functionality.
The grounds for deprecation (and eventually removal) are as follows:
* Alternative functions exist which are more descriptive, easily understood, and more readily searchable (for example, many common Google searches omit the “`” token entirely when searching).
* Backticks are visually easily confused with single quotes despite exhibiting radically different behaviour.
* It could be considered unintuitive that single quoted strings do not support variable substitution, but single backticks do. This is something that is only covered in the user contributed notes (EN).
* It could be considered unintuitive that backticks already rely on the security settings for shell_exec despite not being obviously connected.
Backward Incompatible Changes
Although the deprecation notice itself will carry no backwards compatibility changes, this RFC is written with the intent that the backtick operator would eventually be removed in a later version.
Should the operator eventually be removed, there would be a BC break that would require code using it to be updated to reflect the alternative mechanisms documented in “Program Execution Functions”, specifically shell_exec which is functionally identical.
For most cases, this should be an easy upgrade route as there is a 1-to-1 replacement between `expression` and shell_exec(“expression”), and should complete removal eventually become viable, scripts could be provided (as well as plugins for existing code re-writers) that would make this a trivial operation to upgrade.
Proposed PHP Version(s)
Use of the execution operator would be deprecated in PHP 8.0 with a mind to remove it in a later version.
This change is most likely to affect code written in a style that uses PHP in a similar style to BASH or other shells. The impact of this RFC in isolation would be limited to a deprecation notice being issued.
This RFC lays the groundwork for the eventual removal of the backtick / execution operator.
Proposed Voting Choices
Yes / No vote to deprecate the backtick operator requiring a 2/3rds majority.
https://wiki.php.net/rfc/deprecate-backtick-operator (never brought to vote)