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

RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_backticks_as_an_alias_for_shell_exec
This commit is contained in:
Tim Düsterhus 2025-08-12 12:02:13 +02:00 committed by GitHub
parent 4d6dde595c
commit 3d9d68e1ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
54 changed files with 225 additions and 112 deletions

2
NEWS
View file

@ -9,6 +9,8 @@ PHP NEWS
been deprecated, as it no longer has any effect since PHP 8.0. (Girgias) been deprecated, as it no longer has any effect since PHP 8.0. (Girgias)
. Terminating case statements with a semicolon instead of a colon has . Terminating case statements with a semicolon instead of a colon has
been deprecated. (theodorejb) been deprecated. (theodorejb)
. The backtick operator as an alias for shell_exec() has been deprecated.
(timwolla)
- DOM: - DOM:
. Fixed bug GH-18877 (\Dom\HTMLDocument querySelectorAll selecting only the . Fixed bug GH-18877 (\Dom\HTMLDocument querySelectorAll selecting only the

View file

@ -328,6 +328,8 @@ PHP 8.5 UPGRADE NOTES
. Terminating case statements with a semicolon instead of a colon has . Terminating case statements with a semicolon instead of a colon has
been deprecated. been deprecated.
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_semicolon_after_case_in_switch_statement RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_semicolon_after_case_in_switch_statement
. The backtick operator as an alias for shell_exec() has been deprecated.
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_backticks_as_an_alias_for_shell_exec
- FileInfo: - FileInfo:
. The finfo_close() function has been deprecated. . The finfo_close() function has been deprecated.

View file

@ -8,7 +8,7 @@ if (extension_loaded("readline")) die("skip Test doesn't support readline");
<?php <?php
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
$cmd = "$php -n -d memory_limit=4M -a \"".__DIR__."\"/bug40236.inc"; $cmd = "$php -n -d memory_limit=4M -a \"".__DIR__."\"/bug40236.inc";
echo `$cmd`; echo shell_exec($cmd);
?> ?>
--EXPECT-- --EXPECT--
Interactive shell (-a) requires the readline extension. Interactive shell (-a) requires the readline extension.

View file

@ -28,7 +28,7 @@ if (PHP_OS == 'Linux') {
} }
} }
elseif (PHP_OS == 'FreeBSD') { elseif (PHP_OS == 'FreeBSD') {
$lines = explode("\n",`sysctl -a`); $lines = explode("\n", shell_exec("sysctl -a"));
$infos = array(); $infos = array();
foreach ($lines as $line) { foreach ($lines as $line) {
if (!$line){ if (!$line){

View file

@ -17,5 +17,12 @@ function show_outputa($prepend, $output) {
show_outputa('Files: ', `cd .`); // this works as expected 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 Okey

View file

@ -10847,6 +10847,8 @@ static void zend_compile_shell_exec(znode *result, zend_ast *ast) /* {{{ */
zval fn_name; zval fn_name;
zend_ast *name_ast, *args_ast, *call_ast; 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"); ZVAL_STRING(&fn_name, "shell_exec");
name_ast = zend_ast_create_zval(&fn_name); name_ast = zend_ast_create_zval(&fn_name);
args_ast = zend_ast_create_list(1, ZEND_AST_ARG_LIST, expr_ast); args_ast = zend_ast_create_list(1, ZEND_AST_ARG_LIST, expr_ast);

View file

@ -30,7 +30,7 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
@rmdir($link); @rmdir($link);
$ln = str_replace('/', '\\', $link); $ln = str_replace('/', '\\', $link);
$d1 = realpath($dir1); $d1 = realpath($dir1);
`mklink /j $ln $d1`; shell_exec("mklink /j $ln $d1");
} else { } else {
@unlink($link); @unlink($link);
@symlink($dir1, $link); @symlink($dir1, $link);
@ -45,7 +45,7 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
@rmdir($link); @rmdir($link);
$ln = str_replace('/', '\\', $link); $ln = str_replace('/', '\\', $link);
$d2 = realpath($dir2); $d2 = realpath($dir2);
`mklink /j $ln $d2`; shell_exec("mklink /j $ln $d2");
} else { } else {
@unlink($link); @unlink($link);
@symlink($dir2, $link); @symlink($dir2, $link);

View file

@ -225,13 +225,13 @@ class PharCommand extends CLICommand
} }
} }
if ($pear) { 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'))); $apiver = trim(substr($apiver, strlen('API Version')));
} }
if ($apiver) { if ($apiver) {
self::notice("PEAR package PHP_Archive: API Version: $apiver.\n"); self::notice("PEAR package PHP_Archive: API Version: $apiver.\n");
$files = explode("\n", (string) `pear list-files PHP_Archive`); $files = explode("\n", (string) shell_exec("pear list-files PHP_Archive"));
$phpdir = (string) `pear config-get php_dir 2>/dev/null`; $phpdir = (string) shell_exec("pear config-get php_dir 2>/dev/null");
$phpdir = trim($phpdir); $phpdir = trim($phpdir);
self::notice("PEAR package PHP_Archive: $phpdir.\n"); self::notice("PEAR package PHP_Archive: $phpdir.\n");
if (is_dir($phpdir)) { if (is_dir($phpdir)) {

View file

@ -55,7 +55,7 @@ ob_end_flush();
?>'); ?>');
$extra_arguments = getenv('TEST_PHP_EXTRA_ARGS'); $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); unlink($file);

View file

@ -18,7 +18,7 @@ $junk0 = $base . DIRECTORY_SEPARATOR . "Серёжка2";
mkdir($base); mkdir($base);
mkdir($dir0); mkdir($dir0);
mkdir($dir1); mkdir($dir1);
`mklink /J $junk0 $dir0`; shell_exec("mklink /J $junk0 $dir0");
var_dump( var_dump(
readlink($dir0), readlink($dir0),

View file

@ -11,13 +11,13 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
var_dump(mkdir("mkdir-002", 0777)); var_dump(mkdir("mkdir-002", 0777));
var_dump(mkdir("mkdir-002/subdir", 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/subdir"));
var_dump(rmdir("mkdir-002")); var_dump(rmdir("mkdir-002"));
var_dump(mkdir("./mkdir-002", 0777)); var_dump(mkdir("./mkdir-002", 0777));
var_dump(mkdir("./mkdir-002/subdir", 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/subdir"));
var_dump(rmdir("./mkdir-002")); var_dump(rmdir("./mkdir-002"));
@ -25,7 +25,7 @@ var_dump(mkdir(__DIR__."/mkdir-002", 0777));
var_dump(mkdir(__DIR__."/mkdir-002/subdir", 0777)); var_dump(mkdir(__DIR__."/mkdir-002/subdir", 0777));
$dirname = __DIR__."/mkdir-002"; $dirname = __DIR__."/mkdir-002";
$dirname_escaped = escapeshellarg($dirname); $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/subdir"));
var_dump(rmdir(__DIR__."/mkdir-002")); var_dump(rmdir(__DIR__."/mkdir-002"));

View file

@ -10,7 +10,7 @@ include "include.inc";
$php = get_cgi_path(); $php = get_cgi_path();
reset_env_vars(); reset_env_vars();
var_dump(`$php -n -v`); var_dump(shell_exec("$php -n -v"));
echo "Done\n"; echo "Done\n";
?> ?>

View file

@ -15,13 +15,13 @@ $file = __DIR__."/002.test.php";
file_put_contents($file, '<?php var_dump(ini_get("max_execution_time")); ?>'); file_put_contents($file, '<?php var_dump(ini_get("max_execution_time")); ?>');
var_dump(`$php -n -d max_execution_time=111 $file`); var_dump(shell_exec("$php -n -d max_execution_time=111 $file"));
var_dump(`$php -n -d max_execution_time=500 $file`); var_dump(shell_exec("$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=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")); ?>'); 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); unlink($file);

View file

@ -37,9 +37,15 @@ class test { /* {{{ */
file_put_contents($filename, $code); file_put_contents($filename, $code);
var_dump(`$php -n -w "$filename"`); var_dump(shell_exec(<<<SHELL
var_dump(`$php -n -w "wrong"`); $php -n -w "$filename"
var_dump(`echo "<?php /* comment */ class test {\n // comment \n function foo() {} } ?>" | $php -n -w`); 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); @unlink($filename);

View file

@ -27,11 +27,17 @@ var_dump(test::$pri);
file_put_contents($filename, $code); file_put_contents($filename, $code);
if (defined("PHP_WINDOWS_VERSION_MAJOR")) { if (defined("PHP_WINDOWS_VERSION_MAJOR")) {
var_dump(`$php -n -f "$filename"`); var_dump(shell_exec(<<<SHELL
$php -n -f "$filename"
SHELL));
} else { } 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); @unlink($filename);

View file

@ -10,8 +10,12 @@ include "include.inc";
$php = get_cgi_path(); $php = get_cgi_path();
reset_env_vars(); reset_env_vars();
var_dump(`$php -n -a -f "wrong"`); var_dump(shell_exec(<<<SHELL
var_dump(`$php -n -f "wrong" -a`); $php -n -a -f "wrong"
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -f "wrong" -a
SHELL));
echo "Done\n"; echo "Done\n";
?> ?>

View file

@ -29,8 +29,12 @@ echo test::$var;
file_put_contents($filename, $code); file_put_contents($filename, $code);
var_dump(`"$php" -n -l "$filename"`); var_dump(shell_exec(<<<SHELL
var_dump(`"$php" -n -l some.unknown`); "$php" -n -l "$filename"
SHELL));
var_dump(shell_exec(<<<SHELL
"$php" -n -l some.unknown
SHELL));
$code = ' $code = '
<?php <?php
@ -45,9 +49,13 @@ class test
file_put_contents($filename, $code); file_put_contents($filename, $code);
if (defined("PHP_WINDOWS_VERSION_MAJOR")) { if (defined("PHP_WINDOWS_VERSION_MAJOR")) {
var_dump(`"$php" -n -l "$filename"`); var_dump(shell_exec(<<<SHELL
"$php" -n -l "$filename"
SHELL));
} else { } 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); @unlink($filename);

View file

@ -9,8 +9,12 @@ include "include.inc";
$php = get_cgi_path(); $php = get_cgi_path();
reset_env_vars(); reset_env_vars();
var_dump(`"$php" -n -f some.php -f some.php`); var_dump(shell_exec(<<<SHELL
var_dump(`"$php" -n -s -w -l`); "$php" -n -f some.php -f some.php
SHELL));
var_dump(shell_exec(<<<SHELL
"$php" -n -s -w -l
SHELL));
?> ?>
--EXPECT-- --EXPECT--

View file

@ -30,8 +30,12 @@ $o = new test;
file_put_contents($filename, $code); file_put_contents($filename, $code);
var_dump(`"$php" -n -s "$filename"`); var_dump(shell_exec(<<<SHELL
var_dump(`"$php" -n -s "unknown"`); "$php" -n -s "$filename"
SHELL));
var_dump(shell_exec(<<<SHELL
"$php" -n -s "unknown"
SHELL));
@unlink($filename); @unlink($filename);

View file

@ -16,7 +16,7 @@ putenv("TRANSLATED_PATH=".$f."/x");
putenv("SCRIPT_FILENAME=".$f."/x"); putenv("SCRIPT_FILENAME=".$f."/x");
file_put_contents($f, '<?php var_dump($_SERVER["TRANSLATED_PATH"]); ?>'); file_put_contents($f, '<?php var_dump($_SERVER["TRANSLATED_PATH"]); ?>');
echo (`$php -n $f`); echo shell_exec("$php -n $f");
echo "Done\n"; echo "Done\n";

View file

@ -19,19 +19,19 @@ header("HTTP/1.1 403 Forbidden");
header("Status: 403 Also Forbidden"); header("Status: 403 Also Forbidden");
?>'); ?>');
echo (`$php -n $f`); echo shell_exec("$php -n $f");
file_put_contents($f, '<?php file_put_contents($f, '<?php
header("HTTP/1.1 403 Forbidden"); header("HTTP/1.1 403 Forbidden");
?>'); ?>');
echo (`$php -n $f`); echo shell_exec("$php -n $f");
file_put_contents($f, '<?php file_put_contents($f, '<?php
header("Status: 403 Also Forbidden"); header("Status: 403 Also Forbidden");
?>'); ?>');
echo (`$php -n $f`); echo shell_exec("$php -n $f");
echo "Done\n"; echo "Done\n";

View file

@ -9,7 +9,7 @@ function get_cgi_path() /* {{{ */
$cgi = false; $cgi = false;
if (file_exists($php) && is_executable($php)) { if (file_exists($php) && is_executable($php)) {
$version = `$php_escaped -n -v`; $version = shell_exec("$php_escaped -n -v");
if (strstr($version, "(cli)")) { if (strstr($version, "(cli)")) {
/* that's cli */ /* that's cli */
$cli = true; $cli = true;

View file

@ -7,7 +7,7 @@ version string
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
var_dump(`$php -n -v`); var_dump(shell_exec("$php -n -v"));
echo "Done\n"; echo "Done\n";
?> ?>

View file

@ -12,7 +12,9 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $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"; echo "Done\n";
?> ?>

View file

@ -9,7 +9,9 @@ include "skipif.inc";
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $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"; echo "Done\n";
?> ?>

View file

@ -12,8 +12,12 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
var_dump(`$php -nd max_execution_time=111 -r 'var_dump(ini_get("max_execution_time"));'`); var_dump(shell_exec(<<<SHELL
var_dump(`$php -nd max_execution_time=500 -r 'var_dump(ini_get("max_execution_time"));'`); $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-- --EXPECT--

View file

@ -12,10 +12,18 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $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(shell_exec(<<<SHELL
var_dump(`$php -n -d max_execution_time=500 -r 'var_dump(ini_get("max_execution_time"));'`); $php -n -d max_execution_time=111 -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"));'`); SHELL));
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=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"; echo "Done\n";
?> ?>

View file

@ -9,9 +9,9 @@ include "skipif.inc";
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
var_dump(`$php -n --rf unknown`); var_dump(shell_exec("$php -n --rf unknown"));
var_dump(`$php -n --rf echo`); var_dump(shell_exec("$php -n --rf echo"));
var_dump(`$php -n --rf phpinfo`); var_dump(shell_exec("$php -n --rf phpinfo"));
echo "Done\n"; echo "Done\n";
?> ?>

View file

@ -9,9 +9,9 @@ include "skipif.inc";
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
var_dump(`$php -n --rc unknown`); var_dump(shell_exec("$php -n --rc unknown"));
var_dump(`$php -n --rc stdclass`); var_dump(shell_exec("$php -n --rc stdclass"));
var_dump(`$php -n --rc exception`); var_dump(shell_exec("$php -n --rc exception"));
echo "Done\n"; echo "Done\n";
?> ?>

View file

@ -17,9 +17,11 @@ date.timezone=UTC
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
var_dump(`$php -n --re unknown`); var_dump(shell_exec("$php -n --re unknown"));
var_dump(`$php -n --re ""`); var_dump(shell_exec(<<<SHELL
var_dump(`$php -n --re pcre`); $php -n --re ""
SHELL));
var_dump(shell_exec("$php -n --re pcre"));
echo "Done\n"; echo "Done\n";
?> ?>

View file

@ -32,9 +32,15 @@ class test { /* {{{ */
file_put_contents($filename, $code); file_put_contents($filename, $code);
var_dump(`$php -n -w "$filename"`); var_dump(shell_exec(<<<SHELL
var_dump(`$php -n -w "wrong"`); $php -n -w "$filename"
var_dump(`echo "<?php /* comment */ class test {\n // comment \n function foo() {} } ?>" | $php -n -w`); 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); @unlink($filename);

View file

@ -26,8 +26,12 @@ var_dump(test::$pri);
file_put_contents($filename, $code); file_put_contents($filename, $code);
var_dump(`$php -n -f "$filename"`); var_dump(shell_exec(<<<SHELL
var_dump(`$php -n -f "wrong"`); $php -n -f "$filename"
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -f "wrong"
SHELL));
@unlink($filename); @unlink($filename);

View file

@ -9,8 +9,12 @@ readline
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
var_dump(`$php -n -a -r "echo hello;"`); var_dump(shell_exec(<<<SHELL
var_dump(`$php -n -r "echo hello;" -a`); $php -n -a -r "echo hello;"
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -r "echo hello;" -a
SHELL));
echo "Done\n"; echo "Done\n";
?> ?>

View file

@ -22,7 +22,9 @@ hello
file_put_contents($filename_txt, $txt); file_put_contents($filename_txt, $txt);
var_dump(`cat $filename_txt_escaped | $php -n -R "var_dump(1);"`); var_dump(shell_exec(<<<SHELL
cat $filename_txt_escaped | $php -n -R "var_dump(1);"
SHELL));
@unlink($filename_txt); @unlink($filename_txt);

View file

@ -31,7 +31,7 @@ hello';
file_put_contents($filename_txt, $txt); file_put_contents($filename_txt, $txt);
var_dump(`cat $filename_txt_escaped | $php -n -F $filename_escaped`); var_dump(shell_exec("cat $filename_txt_escaped | $php -n -F $filename_escaped"));
?> ?>
--CLEAN-- --CLEAN--

View file

@ -26,8 +26,8 @@ echo test::$var;
file_put_contents($filename, $code); file_put_contents($filename, $code);
var_dump(`$php -n -l $filename_escaped`); var_dump(shell_exec("$php -n -l $filename_escaped"));
var_dump(`$php -n -l some.unknown`); var_dump(shell_exec("$php -n -l some.unknown"));
$code = ' $code = '
<?php <?php
@ -41,7 +41,7 @@ class test
file_put_contents($filename, $code); file_put_contents($filename, $code);
var_dump(`$php -n -l $filename_escaped`); var_dump(shell_exec("$php -n -l $filename_escaped"));
@unlink($filename); @unlink($filename);

View file

@ -15,17 +15,39 @@ $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
// -s : behavior = HIGHLIGHT // -s : behavior = HIGHLIGHT
// -w : behavior = STRIP // -w : behavior = STRIP
var_dump(`$php -n -r "echo 1;" -F some.php`); var_dump(shell_exec(<<<SHELL
var_dump(`$php -n -r "echo 2;" -f some.php`); $php -n -r "echo 1;" -F some.php
var_dump(`$php -n -r "echo 3;" -l`); // ignores linting SHELL));
var_dump(`$php -n -r "echo 4;" -R some.php`); var_dump(shell_exec(<<<SHELL
var_dump(`$php -n -r "echo 5;" -B ""`); $php -n -r "echo 2;" -f some.php
var_dump(`$php -n -a -B ""`); SHELL));
var_dump(`$php -n -r "echo 6;" -E ""`); var_dump(shell_exec(<<<SHELL
var_dump(`$php -n -a -E ""`); $php -n -r "echo 3;" -l
var_dump(`$php -n -r "echo 7;" -s`); SHELL)); // ignores linting
var_dump(`$php -n -r "echo 8;" -w`); var_dump(shell_exec(<<<SHELL
var_dump(`$php -n -l -r "echo 9;"`); $php -n -r "echo 4;" -R some.php
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -r "echo 5;" -B ""
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -a -B ""
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -r "echo 6;" -E ""
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -a -E ""
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -r "echo 7;" -s
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -r "echo 8;" -w
SHELL));
var_dump(shell_exec(<<<SHELL
$php -n -l -r "echo 9;"
SHELL));
echo "Done\n"; echo "Done\n";
?> ?>

View file

@ -7,14 +7,14 @@ invalid arguments and error messages
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
var_dump(`$php -n -F some.php -F some.php`); var_dump(shell_exec("$php -n -F some.php -F some.php"));
var_dump(`$php -n -F some.php -R some.php`); var_dump(shell_exec("$php -n -F some.php -R some.php"));
var_dump(`$php -n -R some.php -F some.php`); var_dump(shell_exec("$php -n -R some.php -F some.php"));
var_dump(`$php -n -R some.php -R some.php`); var_dump(shell_exec("$php -n -R some.php -R some.php"));
var_dump(`$php -n -f some.php -f some.php`); var_dump(shell_exec("$php -n -f some.php -f some.php"));
var_dump(`$php -n -B '' -B ''`); var_dump(shell_exec("$php -n -B '' -B ''"));
var_dump(`$php -n -E '' -E ''`); var_dump(shell_exec("$php -n -E '' -E ''"));
var_dump(`$php -n -r '' -r ''`); var_dump(shell_exec("$php -n -r '' -r ''"));
echo "Done\n"; echo "Done\n";
?> ?>

View file

@ -16,9 +16,15 @@ $filename_txt = __DIR__."/013.test.txt";
$filename_txt_escaped = escapeshellarg($filename_txt); $filename_txt_escaped = escapeshellarg($filename_txt);
file_put_contents($filename_txt, "test\nfile\ncontents\n"); file_put_contents($filename_txt, "test\nfile\ncontents\n");
var_dump(`cat $filename_txt_escaped | $php -n -B 'var_dump("start");'`); var_dump(shell_exec(<<<SHELL
var_dump(`cat $filename_txt_escaped | $php -n -E 'var_dump("end");'`); cat $filename_txt_escaped | $php -n -B 'var_dump("start");'
var_dump(`cat $filename_txt_escaped | $php -n -B 'var_dump("start");' -E 'var_dump("end");'`); SHELL));
var_dump(shell_exec(<<<SHELL
cat $filename_txt_escaped | $php -n -E 'var_dump("end");'
SHELL));
var_dump(shell_exec(<<<SHELL
cat $filename_txt_escaped | $php -n -B 'var_dump("start");' -E 'var_dump("end");'
SHELL));
@unlink($filename_txt); @unlink($filename_txt);

View file

@ -28,8 +28,8 @@ $o = new test;
file_put_contents($filename, $code); file_put_contents($filename, $code);
$filename_escaped = escapeshellarg($filename); $filename_escaped = escapeshellarg($filename);
var_dump(`$php -n -s $filename_escaped`); var_dump(shell_exec("$php -n -s $filename_escaped"));
var_dump(`$php -n -s unknown`); var_dump(shell_exec("$php -n -s unknown"));
@unlink($filename); @unlink($filename);

View file

@ -13,10 +13,12 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
echo `$php -n --version | grep built:`; echo shell_exec("$php -n --version | grep built:");
echo `echo "<?php print_r(\\\$argv);" | $php -n -- foo bar baz`, "\n"; echo shell_exec(<<<SHELL
echo `$php -n --version foo bar baz | grep built:`; echo "<?php print_r(\\\$argv);" | $php -n -- foo bar baz
echo `$php -n --notexisting foo bar baz 2>&1 | grep Usage:`; SHELL), "\n";
echo shell_exec("$php -n --version foo bar baz | grep built:");
echo shell_exec("$php -n --notexisting foo bar baz 2>&1 | grep Usage:");
echo "Done\n"; echo "Done\n";
?> ?>

View file

@ -56,7 +56,7 @@ EOT;
foreach ($codes as $key => $code) { foreach ($codes as $key => $code) {
echo "\n--------------\nSnippet no. $key:\n--------------\n"; echo "\n--------------\nSnippet no. $key:\n--------------\n";
$code = escapeshellarg($code); $code = escapeshellarg($code);
echo `echo $code | $php -a`, "\n"; echo shell_exec("echo $code | $php -a"), "\n";
} }
echo "\nDone\n"; echo "\nDone\n";

View file

@ -13,7 +13,7 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
echo `$php -n -m`; echo shell_exec("$php -n -m");
echo "Done\n"; echo "Done\n";
?> ?>

View file

@ -13,7 +13,7 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
echo `$php -n -i`; echo shell_exec("$php -n -i");
echo "\nDone\n"; echo "\nDone\n";
?> ?>

View file

@ -13,8 +13,8 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
echo `$php -n --ri this_extension_does_not_exist_568537753423`; echo shell_exec("$php -n --ri this_extension_does_not_exist_568537753423");
echo `$php -n --ri standard`; echo shell_exec("$php -n --ri standard");
echo "\nDone\n"; echo "\nDone\n";
?> ?>

View file

@ -31,7 +31,7 @@ $script = "#!$php -n\n".
file_put_contents($filename, $script); file_put_contents($filename, $script);
chmod($filename, 0777); chmod($filename, 0777);
echo `$filename`; echo shell_exec($filename);
echo "\nDone\n"; echo "\nDone\n";
?> ?>

View file

@ -11,7 +11,7 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
<?php <?php
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
$output = `$php -n -i`; $output = shell_exec("$php -n -i");
var_dump(str_contains($output, "extension_dir => ")); var_dump(str_contains($output, "extension_dir => "));
?> ?>

View file

@ -13,7 +13,7 @@ $argv_fl = __DIR__ . DIRECTORY_SEPARATOR . "argv_test.php";
$argv_fl_escaped = escapeshellarg($argv_fl); $argv_fl_escaped = escapeshellarg($argv_fl);
file_put_contents($argv_fl, "<?php var_dump(\$argv); ?>"); file_put_contents($argv_fl, "<?php var_dump(\$argv); ?>");
var_dump(`$php -n $argv_fl_escaped 多字节字符串 マルチバイト文字列 многобайтоваястрока flerbytesträng`); var_dump(shell_exec("$php -n $argv_fl_escaped 多字节字符串 マルチバイト文字列 многобайтоваястрока flerbytesträng"));
@unlink($argv_fl); @unlink($argv_fl);

View file

@ -24,7 +24,7 @@ $out_fl = __DIR__ . "\\argv_bug77111.txt";
$argv_fl = __DIR__ . DIRECTORY_SEPARATOR . "argv_bug77111_test.php"; $argv_fl = __DIR__ . DIRECTORY_SEPARATOR . "argv_bug77111_test.php";
file_put_contents($argv_fl, "<?php file_put_contents('$out_fl', implode(' ', array_slice(\$argv, 1))); ?>"); file_put_contents($argv_fl, "<?php file_put_contents('$out_fl', implode(' ', array_slice(\$argv, 1))); ?>");
`$php -n $argv_fl Ästhetik Æstetik Esthétique Estética Эстетика`; shell_exec("$php -n $argv_fl Ästhetik Æstetik Esthétique Estética Эстетика");
var_dump(file_get_contents($out_fl)); var_dump(file_get_contents($out_fl));
?> ?>

View file

@ -22,9 +22,11 @@ file_put_contents($filename_txt, $txt);
$test_args = ['$argi', '$argn']; $test_args = ['$argi', '$argn'];
foreach ($test_args as $test_arg) { foreach ($test_args as $test_arg) {
if (substr(PHP_OS, 0, 3) == 'WIN') { if (substr(PHP_OS, 0, 3) == 'WIN') {
var_dump(`type $filename_txt_escaped | $php -n -R "echo $test_arg . PHP_EOL;"`); var_dump(shell_exec(<<<SHELL
type $filename_txt_escaped | $php -n -R "echo $test_arg . PHP_EOL;"
SHELL));
} else { } else {
var_dump(`cat $filename_txt_escaped | $php -n -R 'echo $test_arg . PHP_EOL;'`); var_dump(shell_exec("cat $filename_txt_escaped | $php -n -R 'echo $test_arg . PHP_EOL;'"));
} }
} }

View file

@ -27,7 +27,9 @@ exit
EOT; EOT;
$code = escapeshellarg($code); $code = escapeshellarg($code);
echo `echo $code | "$php" -a`, "\n"; echo shell_exec(<<<SHELL
echo $code | "$php" -a
SHELL), "\n";
?> ?>
--EXPECT-- --EXPECT--
Interactive shell Interactive shell

View file

@ -9,7 +9,7 @@ require_once "tester.inc";
$php = \FPM\Tester::findExecutable(); $php = \FPM\Tester::findExecutable();
var_dump(`$php -n -v`); var_dump(shell_exec("$php -n -v"));
echo "Done\n"; echo "Done\n";
?> ?>

View file

@ -11,7 +11,7 @@ $phpdbg = getenv('TEST_PHPDBG_EXECUTABLE_ESCAPED');
chdir(__DIR__."/bug73615"); chdir(__DIR__."/bug73615");
print `$phpdbg -qn`; print shell_exec("$phpdbg -qn");
?> ?>
--EXPECT-- --EXPECT--

View file

@ -5,7 +5,7 @@ openssl
--SKIPIF-- --SKIPIF--
<?php <?php
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
if (false !== stripos(`$php -n -m`, 'openssl')) { if (false !== stripos(shell_exec("$php -n -m"), 'openssl')) {
die('skip openssl is built static'); die('skip openssl is built static');
} }
$ext_module = ini_get('extension_dir') . DIRECTORY_SEPARATOR . (substr(PHP_OS, 0, 3) === "WIN" ? "php_openssl." : "openssl.") . PHP_SHLIB_SUFFIX; $ext_module = ini_get('extension_dir') . DIRECTORY_SEPARATOR . (substr(PHP_OS, 0, 3) === "WIN" ? "php_openssl." : "openssl.") . PHP_SHLIB_SUFFIX;