2

i have a script like this :

<html>
<body>

<?php
require("wrongFile.php");
echo "Hello World!";
?>

</body>
</html>

now if wrongfile not exists the two below error will report:

Warning: require(wrongFile.php) [function.require]: failed to open stream: No such file or directory in C:\home\website\test.php on line 5

Fatal error: require() [function.require]:Failed opening required 'wrongFile.php' (include_path='.;C:\php5\pear') in C:\home\website\test.php on line 5

i know that if not exists file in require() function a fatal error displayed that cause script execution stop but do not understand what is first error

the first error display in using of include() function too

Community
  • 1
  • 1
Ahmad Badpey
  • 6,348
  • 16
  • 93
  • 159

2 Answers2

6

It's pretty obvious, isn't it? :-)

The first warning is thrown from within the require() function, when it tries to open the file you specified. It can't open a stream, which is used to read the file, because the file doesn't exist.

Because of that, the function call itself also fails, which explains the 'Fatal error'.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
0

The first is warning, not error. You can try using @include to suppress it. (naturally, it's of no great use with require).

Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173