-1

Steps to regenerate the issue :

There are total 3 files

include.php contains :

<?php
    $var1 = 5 + $var1;
?>

require.php contains :

<?php
    $var2 = 5 + $var2;
?>

incvsreq.php will contain :

<?php
$var1 = 0; // Starting with 0

include('include.php'); // Includes the file so Adding 5 + 0

echo $var1.'<br/>'; // Result 5

include_once('include.php'); // Will not include as it is already included

echo $var1.'<br/>'; // Display again 5, as it was not included above

include('include.php'); // This will include again so 5 + 5

echo $var1; // Result 10

rename('include.php', '_include.php'); // Rename the file

include('include.php'); // Warning should occur on this line as the file is not present now, but the script should continue.

$var2 = 0; // Starting with 0

require('require.php'); // Includes the file so Adding 5 + 0

echo $var2.'<br/>'; // Result 5

require_once('require.php'); // Will not include as it is already included

echo $var2.'<br/>'; // Display again 5, as it was not included above

require('require.php'); // This will include again so 5 + 5

echo $var2; // Result 10

rename('require.php', '_require.php'); // Rename the file

require('require.php'); // ERROR should occur on this line as the file is not present now, and the script should not continue.

echo 'This is not displayed'; // This won't be displayed.
?>

Output of this script is :

5
5
10
Warning: include(include.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\Ampps\www\include\incvsreq.php on line 23

Warning: include(include.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\Ampps\www\include\incvsreq.php on line 23

Warning: include() [function.include]: Failed opening 'include.php' for inclusion (include_path='.;C:\php\pear') in C:\Program Files\Ampps\www\include\incvsreq.php on line 23
5
5
10
Warning: require(require.php) [function.require]: failed to open stream: No such file or directory in C:\Program Files\Ampps\www\include\incvsreq.php on line 45

Warning: require(require.php) [function.require]: failed to open stream: No such file or directory in C:\Program Files\Ampps\www\include\incvsreq.php on line 45

Fatal error: require() [function.require]: Failed opening required 'require.php' (include_path='.;C:\php\pear') in C:\Program Files\Ampps\www\include\incvsreq.php on line 45

I understood the Fatal Error in the last and 3rd warning from the top but how did other warnings appear ? I am little confused here. I have commented each line for better understanding.

Jigar
  • 3,256
  • 1
  • 30
  • 51
  • possible duplicate of [When should I use require\_once vs include?](http://stackoverflow.com/questions/2418473/when-should-i-use-require-once-vs-include) – zaf Mar 27 '13 at 17:44
  • Well it is acting exactly as you have predicted what is the problem then? And why do you need such a thing? Use at least modular programming and introduce a function. – Volkan Mar 27 '13 at 17:46
  • @zaf : I know what is the difference between require and include. and when to use it. I am just not able to understand those warnings `include(include.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\Ampps\www\include\incvsreq.php on line 23`. @Ihsan : I am not scripting in such a way. These are just test files. I am trying to understand those warnings(1st, 2nd, 4th and 5th). – Jigar Mar 27 '13 at 18:13

2 Answers2

0

understood the Fatal Error in the last and 3rd warning from the top but how did other warnings appear ? I am little confused here.

If you look at the error log in detail. Error messages are being generated only on two lines as you expect. Line 23 and line 45. Even if they are showing 3 times, they are being generated only on those two lines for which you are asking. This code appears to be behaving like it should

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
0

Error line generate an MSG on few different levels of reporting and what get printed out is controlled by error_reporting level set in PHP for more information check PHP Documentation... error_reporting

Borik
  • 438
  • 3
  • 9