xref: /PHP-7.2/ext/standard/tests/file/bug22414.phpt (revision 17ccbeec)
1--TEST--
2Bug #22414 (passthru() does not read data correctly)
3--INI--
4output_handler=
5--FILE--
6<?php
7
8	$php = getenv('TEST_PHP_EXECUTABLE');
9	$tmpfile = tempnam(__DIR__, 'phpt');
10	$args = ' -n -dsafe_mode=off ';
11
12	/* Regular Data Test */
13	passthru($php . $args . ' -r " echo \"HELLO\"; "');
14
15	echo "\n";
16
17	/* Binary Data Test */
18
19	if (substr(PHP_OS, 0, 3) != 'WIN') {
20		$cmd = $php . $args . ' -r \"readfile(@getenv(\'TEST_PHP_EXECUTABLE\')); \"';
21		$cmd = $php . $args . ' -r \' passthru("'.$cmd.'"); \' > '.$tmpfile ;
22	} else {
23		$cmd = $php . $args . ' -r \"readfile(@getenv(\\\\\\"TEST_PHP_EXECUTABLE\\\\\\")); \"';
24		$cmd = $php . $args . ' -r " passthru(\''.$cmd.'\');" > '.$tmpfile ;
25	}
26	exec($cmd);
27
28	if (md5_file($php) == md5_file($tmpfile)) {
29		echo "Works\n";
30	} else {
31		echo "Does not work\n";
32	}
33
34	@unlink($tmpfile);
35?>
36--EXPECT--
37HELLO
38Works
39