ID: 22775 User updated by: gk at proliberty dot com Reported By: gk at proliberty dot com Status: Open Bug Type: CGI related Operating System: linux RH 7.2; kernel 2.4.18 PHP Version: 4.3.2RC1 New Comment:
Actually I was mistaken about the workaround: THERE IS NO WAY TO EXIT CORRECTLY, USING require(); only with include()! Which is contrary to the entire purpose of using require() instead of include(). This does NOT work: <?php $success=require("non_existent_file"); if (!$success) exit(1); ?> This DOES work: <?php $success=include("non_existent_file"); if (!$success) exit(1); ?> Previous Comments: ------------------------------------------------------------------------ [2003-03-18 20:50:53] gk at proliberty dot com According to the manual, require() differs from include() in that failure to open a file is FATAL in require(). Yet, using sapi/cgi/php or sapi/cli/php, fatal errors from require() exit with status=0 instead of non-zero, as one would expect from a 'fatal' error. I do not know if this problem is true for ALL fatal errors or not. Calling exit(1) works correctly however, which provides an awkward, but useful, workaround to this problem: $success=require("non_existent.php"); if (!$success) exit(1); Here is my test file: /htdocs/common/test/junk/test.php <?php $script="non_existent_file"; $success=require_once($script); //the following fixes the problem: //if (!$success) exit(1); ?> [EMAIL PROTECTED] sapi]# cli/php -f /htdocs/common/test/junk/test.php; echo status="$?"; Warning: main(non_existent_file) [http://www.php.net/function.main]: failed to open stream: No such file or directory in /usr/local/apache/htdocs/common/test/junk/test.php on line 4 Fatal error: main() [http://www.php.net/function.require]: Failed opening required 'non_existent_file' (include_path='.:/usr/local/apache/htdocs/common/php:/usr/local/lib/php') in /usr/local/apache/htdocs/common/test/junk/test.php on line 4 status=0 [EMAIL PROTECTED] sapi]# cli/php -r 'exit(1);'; echo status="$?"; status=1 [EMAIL PROTECTED] sapi]# ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=22775&edit=1