Total members 11889 |It is currently Fri Mar 29, 2024 7:15 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Require command do the same things like what you do in include command ,but there is a great different between these commands and it is in case when the called page not found .

In include command . suppose the following code :
Code:
<?php
include("example.php");
echo "Am here !";
?>

if example.php not found you will have the following output :
Code:
Warning: main(example.php): failed to open stream: No such file or directory in /codemiles.com/Folder/test.php on line 2 Warning: main(): Failed opening 'example.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /codemiles.com/Folder/test.php on line 2

Am here !


As you can see "Am here !" is displayed .So echo statements is working even after the warring because the warning don't prevent php script from running after it happen.
In the case of require command :
Code:
<?php
require("example.php");
echo "Am here !";
?>


the output in case "example.php" not found :
Code:
Warning: main(example.php): failed to open stream: No such file or directory in /codemiles.com/Folder/test.php on line 2
Fatal error: main(): Failed opening required 'example.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /codemiles.com/Folder/test.php on line 2


As you see , the echo statement wasn't executed like in case of include .The reason that the "Fatal error " happened in this case stop echo statements from running .

People (PHP programmers ) recommends using require ,because it is meaningless to include a file which is missing or not found .

Thanks ,



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Require vs Include in php
 require immediate help regarding asp.net     -  
 PHP Include     -  
 Using include function     -  
 get include path     -  
 Using include() Within a Loop     -  
 jsp include directive not working     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com