From: lars dot a dot johansson at se dot atlascopco dot com
Operating system: Linux
PHP version: 5.3.0
PHP Bug Type: Unknown/Other Function
Bug description: calling a php script via exec gives 0 as return code not
respecting exit.
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 bug report at http://bugs.php.net/?id=48905&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=48905&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=48905&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=48905&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=48905&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=48905&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=48905&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=48905&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=48905&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=48905&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=48905&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=48905&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=48905&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=48905&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=48905&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48905&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48905&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=48905&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=48905&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=48905&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=48905&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=48905&r=mysqlcfg