note 101449 rejected from function.require by danbrown
| From: | danbrown@php.net | Date: | Fri, 17 Dec 2010 00:15:11 +0000 |
| Subject: | note 101449 rejected from function.require by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175011@lists.php.net to get a copy of this message | ||
Note Submitter: ghoffman at salientdigital dot com
----
I'm not convinced the require( ) documentation is up to date as of PHP 5.3.3. At least, even
though require( ) generates a fatal error if the file cannot be found, it doesn't appear to be
a catchable error. For example:
<?php
try
{
require('foo.php');
}
catch( Exception $e )
{
echo "<p>The file couldn't be found. ". $e->getMessage()
."</p>\n";
}
?>
results in:
Warning: require(foo.php): failed to open stream: No such file or directory in
/Users/username/Sites/website.com/htdocs/tests/trycatchinclude.php on line 9 Call Stack: 0.0016
634552 1. {main}() /Users/username/Sites/website.com/htdocs/tests/trycatchinclude.php:0 Variables in
local scope (#1): $e = *uninitialized*
Fatal error: require(): Failed opening required 'foo.php'
(include_path='.:/usr/lib/php') in
/Users/username/Sites/website.com/htdocs/tests/trycatchinclude.php on line 9 Call Stack: 0.0016
634552 1. {main}() /Users/username/Sites/website.com/htdocs/tests/trycatchinclude.php:0 Variables in
local scope (#1): $e = *uninitialized*
I was expecting only my paragraph.
When doing the same with include( ) instead of require( ) I get two warnings, also not catchable.