--- id: php-magic-constants title: "PHP Magic Constants" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["__LINE__", "__FILE__", "PHP 맀직 μƒμˆ˜"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["php", "programming", "w3schools", "magic-constants"] raw_sources: ["https://www.w3schools.com/php/php_magic_constants.asp"] applied_in: [] github_commit: "" --- # [[PHP Magic Constants]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Magic constants are the opposite of normal constants β€” instead of holding a fixed value defined once, each one dynamically CHANGES based on where in the code it's evaluated (`__LINE__` differs on every line, `__FUNCTION__` differs per function), making them contextual metadata rather than stored values. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Magic constants** β€” 9 predefined constants whose value depends on where they're used, providing script-state info (file, line, class, function, namespace). [S1] - **Naming convention** β€” start and end with double underscores `__`, except `ClassName::class`. [S1] - **Not case-sensitive** β€” `__LINE__` and `__line__` are equivalent. [S1] - **The 9 constants** β€” `__CLASS__`, `__DIR__`, `__FILE__`, `__FUNCTION__`, `__LINE__`, `__METHOD__`, `__NAMESPACE__`, `__TRAIT__`, `ClassName::class`. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - `__CLASS__` β€” class name if used inside a class. [S1] - `__DIR__` β€” directory of the current file. [S1] - `__FILE__` β€” full path + filename. [S1] - `__FUNCTION__` β€” current function name. [S1] - `__LINE__` β€” current line number. [S1] - `__METHOD__` β€” class name + function name combined. [S1] - `__NAMESPACE__` β€” current namespace name. [S1] - `__TRAIT__` β€” current trait name. [S1] - `ClassName::class` β€” fully qualified class name including namespace. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ†ŒμŠ€μ—μ„œ λͺ¨μˆœλ˜λŠ” μ •λ³΄λŠ” λ°œκ²¬λ˜μ§€ μ•ŠμŒ. ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” __LINE__/__FILE__은 디버깅/λ‘œκΉ… μ‹œ μ—λŸ¬ μœ„μΉ˜λ₯Ό μ •ν™•νžˆ κΈ°λ‘ν•˜λŠ” 데 자주 쓰인닀. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Magic constants reflect their context (PHP): ```php echo __LINE__; // current line number echo __FILE__; // full path of this file echo __FUNCTION__; // name of the enclosing function ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[PHP Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[PHP Constants]], [[PHP Operators]], [[PHP OOP Classes Objects]] - **μ°Έμ‘° λ§₯락:** λ¬Έλ§₯ 의쑴적 μƒμˆ˜ β€” μ—°μ‚°μž(Operators) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” PHP Magic Constants β€” https://www.w3schools.com/php/php_magic_constants.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "PHP Magic Constants" page (Astra wiki-curation, P-Reinforce v3.1 format).