### Discussed in https://github.com/orgs/Programming-Language-Practice/discussions/64 <div type='discussions-op-text'> <sup>Originally posted by **JoisFe** March 4, 2023</sup> # 71. 하나의 파일을 여러 곳에서 사용하기 require ## require - include와 같이 다른 페이지를 불러오는 방법으로 require 존재 ### require 사용 방법 ``` reauire "파일 경로와 파일명;" ``` <img width="212" alt="image" src="https://user-images.githubusercontent.com/90208100/222907968-e22043be-0265-481a-a549-c9f0600d9ded.png"> - a.php ``` php <?php echo "hi"; ?> ``` - b.php ``` php <?php require "./a.php"; ?> ``` - b.php를 실행시켜보면 <img width="39" alt="image" src="https://user-images.githubusercontent.com/90208100/222908159-b941d989-7021-4aae-bd73-81894e0725da.png"> - include와 require은 같은 기능을 가짐 - 완전히 같다면 2개로 있을 필요가 없음 즉 차이가 있음 ## include vs require ### include - 불러오는 파일의 경로나 파일명에 문제가 있더라도 오류를 발생시키지 않음 ### require - 불러오는 파일의 경로나 파일명에 문제가 있으면 오류를 발생시킴 <?php include "./nonFile.php"; echo "페이지에 오류는 생기지 않음"; ?> <img width="1161" alt="image" src="https://user-images.githubusercontent.com/90208100/222908701-3e2c95c0-681a-42fd-9dae-a235e4943d64.png"> ``` php <?php require "./nonFile.php"; echo "페이지에 오류 생김"; ?> ``` <img width="725" alt="image" src="https://user-images.githubusercontent.com/90208100/222909436-5c4fb994-81b4-4320-bddc-740d87d21183.png"> ## Reference ### 초보자를 위한 PHP 200제, 정보문화사, [김태영]</div>
Discussed in https://github.com/orgs/Programming-Language-Practice/discussions/64
Originally posted by JoisFe March 4, 2023
71. 하나의 파일을 여러 곳에서 사용하기 require
require
require 사용 방법
reauire "파일 경로와 파일명;"include vs require
include
require
Reference
초보자를 위한 PHP 200제, 정보문화사, [김태영]