note 101449 added to function.require
| From: | ghoffman at salientdigital dot com | Date: | Fri, 17 Dec 2010 00:03:07 +0000 |
| Subject: | note 101449 added to function.require | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175010@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 192.41.42.26
Probable Submitter: 70.166.218.198
----
Manual Page -- http://www.php.net/manual/en/function.require.php
Edit -- https://master.php.net/note/edit/101449
Del: integrated -- https://master.php.net/note/delete/101449/integrated
Del: useless -- https://master.php.net/note/delete/101449/useless
Del: bad code -- https://master.php.net/note/delete/101449/bad+code
Del: spam -- https://master.php.net/note/delete/101449/spam
Del: non-english -- https://master.php.net/note/delete/101449/non-english
Del: in docs -- https://master.php.net/note/delete/101449/in+docs
Del: other reasons-- https://master.php.net/note/delete/101449
Reject -- https://master.php.net/note/reject/101449
Search -- https://master.php.net/manage/user-notes.php