ID:               48905
 Comment by:       sjoerd-php at linuxonly dot nl
 Reported By:      lars dot a dot johansson at se dot atlascopco dot com
 Status:           Open
 Bug Type:         Unknown/Other Function
 Operating System: Linux
 PHP Version:      5.3.0
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[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

Reply via email to