PHP Include And Require Files



Hello , in this section we will learning php function about Include() and Require() like, what is the use of function Include() and Require() , What is differences between 2 of them ? ,  and what is differences using _once in PHP ? .

What Is the use Function of Include() and Require() ?

Function of Include() and Require() is a function are used to insert some php file to other php program , so with this code it'll be helpfull to make program because we don't need to write a code repeatedly and we just need a php file to insert it .


What is the differences between Include() and Require() ?

Actually Include() and Require it's the same function but they just have significant differences , Include() statement will only generate PHP warning but they allow to execute the script to continue if the file to be included cannot be found , while Require statement will generate Fatal Error and stop the script execution. 


What is differences using _once in PHP ?

Using _once in either Include() and Require statement will ensure that only include the file once , wheter it's written repeatedly . If we didn't use _once we will get error if we input the same file more than once.

Lets We Practice this Code !



So i create the data file named as film.php then i make a main  file named welcomepage.php




film.php



 In this file (welcomepage.php) , i already write code Include()

welcomepage.php

Then this is the output

For the Require() has the same output but let's see if we make some error by change code of  film.php to _film.php name , in welcomepage.php 

First we 're using the Include()


Then let's see the output 



As we can see when we using Include() function it'll generate the warning statement but they still
allow to execute the script wheter did'nt found the file.




















Komentar