--- id: php-includes title: "PHP Includes" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["include vs require", "PHP 파일 포함"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["php", "programming", "w3schools", "include", "require"] raw_sources: ["https://www.w3schools.com/php/php_includes.asp"] applied_in: [] github_commit: "" --- # [[PHP Includes]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) `include` and `require` behave identically on SUCCESS but diverge sharply on FAILURE β€” a missing file only produces a warning with `include` (script continues, later code still runs), while the same missing file with `require` triggers a fatal error that halts script execution entirely, making the choice a statement about how critical that file is to the page working at all. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`include 'file';`** / **`require 'file';`** β€” insert a file's content into the calling file. [S1] - **Failure behavior difference** β€” `include` β†’ `E_WARNING`, script continues; `require` β†’ `E_ERROR` (fatal), script stops. [S1] - **When to use `include`** β€” non-critical files like headers, footers, navigation menus (page can still render without them). [S1] - **When to use `require`** β€” critical files like configuration or database connections (page is meaningless without them). [S1] - **Included files share variable scope** β€” variables defined in an included file become usable in the calling file. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Include a footer: ``. [S1] - Include a nav menu: ``. [S1] - Include shares variables: `vars.php` defines `$color='red'; $car='BMW';`; the including file can then `echo "I have a $color $car.";` after `include 'vars.php';`. [S1] - include on missing file (continues): `` β€” the echo still runs (with warning), though `$color`/`$car` are undefined here since the file wasn't found. [S1] - require on missing file (halts): `` β€” the echo NEVER executes; script dies at the require line. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **μ‹€νŒ¨ μ‹œ λ™μž‘μ˜ 근본적 차이**: includeλŠ” 경고만 λ‚΄κ³  μŠ€ν¬λ¦½νŠΈκ°€ 계속 μ‹€ν–‰λ˜μ§€λ§Œ, requireλŠ” 치λͺ…적 μ—λŸ¬λ₯Ό λ‚΄κ³  슀크립트 싀행이 μ™„μ „νžˆ μ€‘λ‹¨λœλ‹€λŠ” 점이 λŒ€λΉ„ 예제둜 직접 증λͺ…됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” λͺ¨λ“  νŽ˜μ΄μ§€κ°€ κ³΅μœ ν•˜λŠ” ν‘œμ€€ 헀더/ν‘Έν„°/메뉴 νŒŒμΌμ„ include둜 μž¬μ‚¬μš©ν•˜λŠ” 것이 μ‹€μ „ μ½”λ“œ μž¬μ‚¬μš©μ˜ λŒ€ν‘œ νŒ¨ν„΄μ΄λ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) require halts execution on failure, unlike include (PHP): ```php ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[PHP Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[PHP Date]], [[PHP Files]], [[PHP Variables Scope]] - **μ°Έμ‘° λ§₯락:** μ½”λ“œ μž¬μ‚¬μš©μ„ μœ„ν•œ 파일 포함 β€” 파일 처리(Files) μ„Ήμ…˜μœΌλ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” PHP Include Files β€” https://www.w3schools.com/php/php_includes.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "PHP Include Files" page (Astra wiki-curation, P-Reinforce v3.1 format).