Skip to content

71. 하나의 파일을 여러 곳에서 사용하기 require #65

@JoisFe

Description

@JoisFe

Discussed in https://github.com/orgs/Programming-Language-Practice/discussions/64

Originally posted by JoisFe March 4, 2023

71. 하나의 파일을 여러 곳에서 사용하기 require

require

  • include와 같이 다른 페이지를 불러오는 방법으로 require 존재

require 사용 방법

reauire "파일 경로와 파일명;"

image
  • a.php
<?php
echo "hi";
?>
  • b.php
<?php
    require "./a.php";
?>
  • b.php를 실행시켜보면
image
  • include와 require은 같은 기능을 가짐
  • 완전히 같다면 2개로 있을 필요가 없음 즉 차이가 있음

include vs require

include

  • 불러오는 파일의 경로나 파일명에 문제가 있더라도 오류를 발생시키지 않음

require

  • 불러오는 파일의 경로나 파일명에 문제가 있으면 오류를 발생시킴
image
<?php
    require "./nonFile.php";
    echo "페이지에 오류 생김";
?>
image

Reference

초보자를 위한 PHP 200제, 정보문화사, [김태영]

Metadata

Metadata

Assignees

No one assigned

    Labels

    200 Solved초보자를 위한 200제 책 학습을 위한 라벨입니다.PHPPHP 관련 라벨입니다.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions