ID: 48905 Updated by: j...@php.net Reported By: lars dot a dot johansson at se dot atlascopco dot com -Status: Open +Status: Bogus Bug Type: Unknown/Other Function Operating System: Linux PHP Version: 5.3.0 New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2009-07-13 17:44:41] sjoerd-php at linuxonly dot nl Thank you for your report. exit() can take either a string or an integer as first parameter. An integer is used as exit code. A string, even if it is numeric, is output on standard out just before exiting. Thus exit(1) will exit with exit code 1, whereas exit("1") will print "1" and exit with error code 0. Because parameters in $argv are strings, you pass a string to exit(), which is printed. You can verify this by printing $output in bugA1.php. ------------------------------------------------------------------------ [2009-07-13 14:02:05] lars dot a dot johansson at se dot atlascopco dot com Description: ------------ Calling a php bug1B.php via exec gives invalid 0 as return code, when picking up 1 from caller when caller is PHP script. You call bug1A.php from a terminal. - ./bug1A.php Script bugA1.php invokes bug1B.php via exec() with parameter '1', which script bug1B.php picks up. It looks like all digits are converted to 0 (zero) if you do not explicit cast $argv[1] to integer. When you call bug1B from a shell script it works like expected, returning 1 as return code. Reproduce code: --------------- #!/home/tooljn/PHP5.3/local/bin/php <?php //this is the caller - bug1A.php $lastOutputLine = exec("./bug1B.php 1", $output, $sysRC); print "return code from bug1B.php rc=$sysRC\n"; ?> #!/home/tooljn/PHP5.3/local/bin/php <?php //this is the called - bug1B.php // If we take away cast (int) string "1" is converted to integer 0 (zero), when called from bug1A.php //if ($argc == 2 and ($argv[1] == '0' or $argv[1] == '1')) $rc = (int) $argv[1]; if ($argc == 2 and ($argv[1] == '0' or $argv[1] == '1')) $rc = $argv[1]; print "bug1B.php rc=$rc\n"; exit($rc); ?> Expected result: ---------------- return code from bug1B.php rc=1; Actual result: -------------- return code from bug1B.php rc=0; ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48905&edit=1