Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • PHP include and require Statements

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 206
    Comment on it

    The include() and require() function takes all the text in a specified file and copies it into the file that uses the these function respectively.

    • include will only produce a warning (E_WARNING) and the script will continue
    • require will produce a fatal error (E_COMPILE_ERROR) and stop the script

    Use the include statement where  you want the execution to go on and show users the output, even if the include file is missing.

    Syntax :

    include <file_name>

    Example

    Example
    
    <?php
    
    include/home/test/public_html/coded/abc.php;
    
    ?>
    

    If in above example if the abc.php does not exists,then still code will run  and it will just generate warning

    Always use the require statement in case of FrameWork, CMS, or a complex PHP application coding, to include a key file to the flow of execution.

    Syntax :

    require <file_name>

    Example

    
    
    <?php
    
    Require /home/test/public_html/coded/abc.php;
    
    ?>
    

    If in above example if the abc.php does not exists,then still code will halt and executes a fatal erroer

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: