-
require_once, namespace : import 시키는 방법PHP 2020. 12. 11. 10:03728x90
PHP 에서 원하는 php 파일을 가져오기 위해서 require_once 와 namespace 를 사용한다
require_once 를 사용할 경우 php 파일을 하나씩 import 할 수 있다
<?php require_once 'greeting.php'; ?>
greeting.php 를 import 시킬 수 있다
namespace 를 사용할 경우 (java 에서 package 와 같다) 여러 php 파일을 import 할 수 있다
<?php namespace greeting\en; class Hi { function __construct() { echo '<h1>hi</h1>'; } } namespace greeting\ko; class Hi { function __construct() { echo '<h1>안녕</h1>'; } } use greeting\en as HiEn; use greeting\ko as HiKo; new HiEn\Hi(); new HiKo\Hi(); ?>
class 2개를 생성하고 greeting 이라는 부모 namespace 에 en, ko 로 자식 namespace 를 두어서 사용했다
728x90728x90'PHP' 카테고리의 다른 글
cookie / session 사용하기 (0) 2020.12.16 PHP parameter 및 return 지정법 (0) 2020.12.11 static 사용 (0) 2020.12.11 SPL : Standard PHP Library (SPL) (0) 2020.12.10