ID:               22775
 Updated by:       [EMAIL PROTECTED]
 Reported By:      gk at proliberty dot com
-Status:           Open
+Status:           Closed
 Bug Type:         CGI related
 Operating System: linux RH 7.2; kernel 2.4.18
 PHP Version:      4.3.2RC1
 New Comment:

This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.




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

[2003-03-19 01:40:19] gk at proliberty dot com

improved the title

------------------------------------------------------------------------

[2003-03-18 21:46:02] gk at proliberty dot com

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);
?>

------------------------------------------------------------------------

[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


Reply via email to