On Ubuntu machine:
$ php -v PHP 5.5.10-1~dotdeb.1 (cli) (built: Mar 6 2014 18:55:59) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with uopz v2.0.4, Copyright (c) 2014, by Joe Watkins <[email protected]> with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
My test.php file is simple:
I would expect this command
php test.php || echo "error" to show “error” but it exits with status code 0.
$ php test.php $ echo $? 0
But on the same machine the same code, but not in file works as expected:
$ php -r "exit(1);" || echo "error" error
$ php -r "exit(1);" $ echo $? 1
On different machine (archlinux) with php:
PHP 5.5.13 (cli) (built: May 29 2014 05:46:58) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
All cases work as expected, even when the code is run from file the status code is 1.
This is a true problem because git hooks depends on this status codes and Jenkins and I couldn’t google it out.
Could it be somehow config-related? I checked cli php.ini and couldn’t find anything suspicious.
uopz extension is the problem. It “corrupts” the exit code. There was a bug opened about this issue.
You can try to set the configuration
uopz.overloads=0 as it was recommended in the bug comments. That, unfortunately didn’t work for me. Only disabling the extension fixed the issue.