Skip to content

zend_compile: Deprecate backticks as an alias for shell_exec() #19443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/tests/bug40236.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (extension_loaded("readline")) die("skip Test doesn't support readline");
<?php
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
$cmd = "$php -n -d memory_limit=4M -a \"".__DIR__."\"/bug40236.inc";
echo `$cmd`;
echo shell_exec($cmd);
?>
--EXPECT--
Interactive shell (-a) requires the readline extension.
2 changes: 1 addition & 1 deletion Zend/tests/bug55509.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if (PHP_OS == 'Linux') {
}
}
elseif (PHP_OS == 'FreeBSD') {
$lines = explode("\n",`sysctl -a`);
$lines = explode("\n", shell_exec("sysctl -a"));
$infos = array();
foreach ($lines as $line) {
if (!$line){
Expand Down
9 changes: 8 additions & 1 deletion Zend/tests/bug64677.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ function show_outputa($prepend, $output) {
show_outputa('Files: ', `cd .`); // this works as expected

?>
--EXPECT--
--EXPECTF--
Deprecated: The backtick (`) operator is deprecated, use shell_exec() instead in %s on line %d

Deprecated: The backtick (`) operator is deprecated, use shell_exec() instead in %s on line %d

Deprecated: The backtick (`) operator is deprecated, use shell_exec() instead in %s on line %d

Deprecated: The backtick (`) operator is deprecated, use shell_exec() instead in %s on line %d
Okey
2 changes: 2 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -10836,6 +10836,8 @@ static void zend_compile_shell_exec(znode *result, zend_ast *ast) /* {{{ */
zval fn_name;
zend_ast *name_ast, *args_ast, *call_ast;

zend_error(E_DEPRECATED, "The backtick (`) operator is deprecated, use shell_exec() instead");

ZVAL_STRING(&fn_name, "shell_exec");
name_ast = zend_ast_create_zval(&fn_name);
args_ast = zend_ast_create_list(1, ZEND_AST_ARG_LIST, expr_ast);
Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/tests/revalidate_path_01.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
@rmdir($link);
$ln = str_replace('/', '\\', $link);
$d1 = realpath($dir1);
`mklink /j $ln $d1`;
shell_exec("mklink /j $ln $d1");
} else {
@unlink($link);
@symlink($dir1, $link);
Expand All @@ -45,7 +45,7 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
@rmdir($link);
$ln = str_replace('/', '\\', $link);
$d2 = realpath($dir2);
`mklink /j $ln $d2`;
shell_exec("mklink /j $ln $d2");
} else {
@unlink($link);
@symlink($dir2, $link);
Expand Down
6 changes: 3 additions & 3 deletions ext/phar/phar/pharcommand.inc
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@ class PharCommand extends CLICommand
}
}
if ($pear) {
$apiver = (string) `pear -q info PHP_Archive 2>/dev/null|grep 'API Version'`;
$apiver = (string) shell_exec("pear -q info PHP_Archive 2>/dev/null|grep 'API Version'");
$apiver = trim(substr($apiver, strlen('API Version')));
}
if ($apiver) {
self::notice("PEAR package PHP_Archive: API Version: $apiver.\n");
$files = explode("\n", (string) `pear list-files PHP_Archive`);
$phpdir = (string) `pear config-get php_dir 2>/dev/null`;
$files = explode("\n", (string) shell_exec("pear list-files PHP_Archive"));
$phpdir = (string) shell_exec("pear config-get php_dir 2>/dev/null");
$phpdir = trim($phpdir);
self::notice("PEAR package PHP_Archive: $phpdir.\n");
if (is_dir($phpdir)) {
Expand Down
2 changes: 1 addition & 1 deletion ext/session/tests/session_regenerate_id_cookie.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ob_end_flush();
?>');

$extra_arguments = getenv('TEST_PHP_EXTRA_ARGS');
var_dump(`$php $extra_arguments -d session.name=PHPSESSID $file`);
var_dump(shell_exec("$php $extra_arguments -d session.name=PHPSESSID $file"));

unlink($file);

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/dir/bug73877.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $junk0 = $base . DIRECTORY_SEPARATOR . "Серёжка2";
mkdir($base);
mkdir($dir0);
mkdir($dir1);
`mklink /J $junk0 $dir0`;
shell_exec("mklink /J $junk0 $dir0");

var_dump(
readlink($dir0),
Expand Down
6 changes: 3 additions & 3 deletions ext/standard/tests/file/mkdir-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {

var_dump(mkdir("mkdir-002", 0777));
var_dump(mkdir("mkdir-002/subdir", 0777));
var_dump(`ls -l mkdir-002`);
var_dump(shell_exec("ls -l mkdir-002"));
var_dump(rmdir("mkdir-002/subdir"));
var_dump(rmdir("mkdir-002"));

var_dump(mkdir("./mkdir-002", 0777));
var_dump(mkdir("./mkdir-002/subdir", 0777));
var_dump(`ls -l ./mkdir-002`);
var_dump(shell_exec("ls -l ./mkdir-002"));
var_dump(rmdir("./mkdir-002/subdir"));
var_dump(rmdir("./mkdir-002"));

var_dump(mkdir(__DIR__."/mkdir-002", 0777));
var_dump(mkdir(__DIR__."/mkdir-002/subdir", 0777));
$dirname = __DIR__."/mkdir-002";
$dirname_escaped = escapeshellarg($dirname);
var_dump(`ls -l $dirname_escaped`);
var_dump(shell_exec("ls -l $dirname_escaped"));
var_dump(rmdir(__DIR__."/mkdir-002/subdir"));
var_dump(rmdir(__DIR__."/mkdir-002"));

Expand Down
2 changes: 1 addition & 1 deletion sapi/cgi/tests/001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include "include.inc";
$php = get_cgi_path();
reset_env_vars();

var_dump(`$php -n -v`);
var_dump(shell_exec("$php -n -v"));

echo "Done\n";
?>
Expand Down
8 changes: 4 additions & 4 deletions sapi/cgi/tests/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ $file = __DIR__."/002.test.php";

file_put_contents($file, '<?php var_dump(ini_get("max_execution_time")); ?>');

var_dump(`$php -n -d max_execution_time=111 $file`);
var_dump(`$php -n -d max_execution_time=500 $file`);
var_dump(`$php -n -d max_execution_time=500 -d max_execution_time=555 $file`);
var_dump(shell_exec("$php -n -d max_execution_time=111 $file"));
var_dump(shell_exec("$php -n -d max_execution_time=500 $file"));
var_dump(shell_exec("$php -n -d max_execution_time=500 -d max_execution_time=555 $file"));

file_put_contents($file, '<?php var_dump(ini_get("max_execution_time")); var_dump(ini_get("upload_tmp_dir")); ?>');

var_dump(`$php -n -d upload_tmp_dir=/test/path -d max_execution_time=555 $file`);
var_dump(shell_exec("$php -n -d upload_tmp_dir=/test/path -d max_execution_time=555 $file"));

unlink($file);

Expand Down
12 changes: 9 additions & 3 deletions sapi/cgi/tests/003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ class test { /* {{{ */

file_put_contents($filename, $code);

var_dump(`$php -n -w "$filename"`);
var_dump(`$php -n -w "wrong"`);
var_dump(`echo "<?php /* comment */ class test {\n // comment \n function foo() {} } ?>" | $php -n -w`);
var_dump(shell_exec(<<<SHELL
$php -n -w "$filename"
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -w "wrong"
SHELL));
var_dump(shell_exec(<<<SHELL
echo "<?php /* comment */ class test {\n // comment \n function foo() {} } ?>" | $php -n -w
SHELL));

@unlink($filename);

Expand Down
12 changes: 9 additions & 3 deletions sapi/cgi/tests/004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ var_dump(test::$pri);
file_put_contents($filename, $code);

if (defined("PHP_WINDOWS_VERSION_MAJOR")) {
var_dump(`$php -n -f "$filename"`);
var_dump(shell_exec(<<<SHELL
$php -n -f "$filename"
SHELL));
} else {
var_dump(`$php -n -f "$filename" 2>/dev/null`);
var_dump(shell_exec(<<<SHELL
$php -n -f "$filename" 2>/dev/null
SHELL));
}
var_dump(`$php -n -f "wrong"`);
var_dump(shell_exec(<<<SHELL
$php -n -f "wrong"
SHELL));

@unlink($filename);

Expand Down
8 changes: 6 additions & 2 deletions sapi/cgi/tests/005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ include "include.inc";
$php = get_cgi_path();
reset_env_vars();

var_dump(`$php -n -a -f "wrong"`);
var_dump(`$php -n -f "wrong" -a`);
var_dump(shell_exec(<<<SHELL
$php -n -a -f "wrong"
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -f "wrong" -a
SHELL));

echo "Done\n";
?>
Expand Down
16 changes: 12 additions & 4 deletions sapi/cgi/tests/006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ echo test::$var;

file_put_contents($filename, $code);

var_dump(`"$php" -n -l "$filename"`);
var_dump(`"$php" -n -l some.unknown`);
var_dump(shell_exec(<<<SHELL
"$php" -n -l "$filename"
SHELL));
var_dump(shell_exec(<<<SHELL
"$php" -n -l some.unknown
SHELL));

$code = '
<?php
Expand All @@ -45,9 +49,13 @@ class test
file_put_contents($filename, $code);

if (defined("PHP_WINDOWS_VERSION_MAJOR")) {
var_dump(`"$php" -n -l "$filename"`);
var_dump(shell_exec(<<<SHELL
"$php" -n -l "$filename"
SHELL));
} else {
var_dump(`"$php" -n -l "$filename" 2>/dev/null`);
var_dump(shell_exec(<<<SHELL
"$php" -n -l "$filename" 2>/dev/null
SHELL));
}

@unlink($filename);
Expand Down
8 changes: 6 additions & 2 deletions sapi/cgi/tests/007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ include "include.inc";
$php = get_cgi_path();
reset_env_vars();

var_dump(`"$php" -n -f some.php -f some.php`);
var_dump(`"$php" -n -s -w -l`);
var_dump(shell_exec(<<<SHELL
"$php" -n -f some.php -f some.php
SHELL));
var_dump(shell_exec(<<<SHELL
"$php" -n -s -w -l
SHELL));

?>
--EXPECT--
Expand Down
8 changes: 6 additions & 2 deletions sapi/cgi/tests/008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ $o = new test;

file_put_contents($filename, $code);

var_dump(`"$php" -n -s "$filename"`);
var_dump(`"$php" -n -s "unknown"`);
var_dump(shell_exec(<<<SHELL
"$php" -n -s "$filename"
SHELL));
var_dump(shell_exec(<<<SHELL
"$php" -n -s "unknown"
SHELL));

@unlink($filename);

Expand Down
2 changes: 1 addition & 1 deletion sapi/cgi/tests/009.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ putenv("TRANSLATED_PATH=".$f."/x");
putenv("SCRIPT_FILENAME=".$f."/x");
file_put_contents($f, '<?php var_dump($_SERVER["TRANSLATED_PATH"]); ?>');

echo (`$php -n $f`);
echo shell_exec("$php -n $f");

echo "Done\n";

Expand Down
6 changes: 3 additions & 3 deletions sapi/cgi/tests/010.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ header("HTTP/1.1 403 Forbidden");
header("Status: 403 Also Forbidden");
?>');

echo (`$php -n $f`);
echo shell_exec("$php -n $f");

file_put_contents($f, '<?php
header("HTTP/1.1 403 Forbidden");
?>');

echo (`$php -n $f`);
echo shell_exec("$php -n $f");

file_put_contents($f, '<?php
header("Status: 403 Also Forbidden");
?>');

echo (`$php -n $f`);
echo shell_exec("$php -n $f");

echo "Done\n";

Expand Down
2 changes: 1 addition & 1 deletion sapi/cgi/tests/include.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function get_cgi_path() /* {{{ */
$cgi = false;

if (file_exists($php) && is_executable($php)) {
$version = `$php_escaped -n -v`;
$version = shell_exec("$php_escaped -n -v");
if (strstr($version, "(cli)")) {
/* that's cli */
$cli = true;
Expand Down
2 changes: 1 addition & 1 deletion sapi/cli/tests/001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version string

$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');

var_dump(`$php -n -v`);
var_dump(shell_exec("$php -n -v"));

echo "Done\n";
?>
Expand Down
4 changes: 3 additions & 1 deletion sapi/cli/tests/002-unix.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {

$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');

var_dump(`$php -n -r 'var_dump("hello");'`);
var_dump(shell_exec(<<<SHELL
$php -n -r 'var_dump("hello");'
SHELL));

echo "Done\n";
?>
Expand Down
4 changes: 3 additions & 1 deletion sapi/cli/tests/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ include "skipif.inc";

$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');

var_dump(`$php -n -r "var_dump('hello');"`);
var_dump(shell_exec(<<<SHELL
$php -n -r "var_dump('hello');"
SHELL));

echo "Done\n";
?>
Expand Down
8 changes: 6 additions & 2 deletions sapi/cli/tests/003-2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {

$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');

var_dump(`$php -nd max_execution_time=111 -r 'var_dump(ini_get("max_execution_time"));'`);
var_dump(`$php -nd max_execution_time=500 -r 'var_dump(ini_get("max_execution_time"));'`);
var_dump(shell_exec(<<<SHELL
$php -nd max_execution_time=111 -r 'var_dump(ini_get("max_execution_time"));'
SHELL));
var_dump(shell_exec(<<<SHELL
$php -nd max_execution_time=500 -r 'var_dump(ini_get("max_execution_time"));'
SHELL));

?>
--EXPECT--
Expand Down
16 changes: 12 additions & 4 deletions sapi/cli/tests/003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {

$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');

var_dump(`$php -n -d max_execution_time=111 -r 'var_dump(ini_get("max_execution_time"));'`);
var_dump(`$php -n -d max_execution_time=500 -r 'var_dump(ini_get("max_execution_time"));'`);
var_dump(`$php -n -d max_execution_time=500 -d max_execution_time=555 -r 'var_dump(ini_get("max_execution_time"));'`);
var_dump(`$php -n -d upload_tmp_dir=/test/path -d max_execution_time=555 -r 'var_dump(ini_get("max_execution_time")); var_dump(ini_get("upload_tmp_dir"));'`);
var_dump(shell_exec(<<<SHELL
$php -n -d max_execution_time=111 -r 'var_dump(ini_get("max_execution_time"));'
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -d max_execution_time=500 -r 'var_dump(ini_get("max_execution_time"));'
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -d max_execution_time=500 -d max_execution_time=555 -r 'var_dump(ini_get("max_execution_time"));'
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -d upload_tmp_dir=/test/path -d max_execution_time=555 -r 'var_dump(ini_get("max_execution_time")); var_dump(ini_get("upload_tmp_dir"));'
SHELL));

echo "Done\n";
?>
Expand Down
6 changes: 3 additions & 3 deletions sapi/cli/tests/004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ include "skipif.inc";

$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');

var_dump(`$php -n --rf unknown`);
var_dump(`$php -n --rf echo`);
var_dump(`$php -n --rf phpinfo`);
var_dump(shell_exec("$php -n --rf unknown"));
var_dump(shell_exec("$php -n --rf echo"));
var_dump(shell_exec("$php -n --rf phpinfo"));

echo "Done\n";
?>
Expand Down
6 changes: 3 additions & 3 deletions sapi/cli/tests/005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ include "skipif.inc";

$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');

var_dump(`$php -n --rc unknown`);
var_dump(`$php -n --rc stdclass`);
var_dump(`$php -n --rc exception`);
var_dump(shell_exec("$php -n --rc unknown"));
var_dump(shell_exec("$php -n --rc stdclass"));
var_dump(shell_exec("$php -n --rc exception"));

echo "Done\n";
?>
Expand Down
Loading