--- 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).