--- id: php-oop-destructor title: "PHP OOP Destructor" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["__destruct()", "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", "oop", "destructor"] raw_sources: ["https://www.w3schools.com/php/php_oop_destructor.asp"] applied_in: [] github_commit: "" --- # [[PHP OOP Destructor]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) `__destruct()` runs automatically at the END of script execution (or when an object is explicitly destroyed) with NO explicit call needed β€” it's the structural mirror of `__construct()`, firing on the opposite lifecycle event (teardown vs. setup) rather than being invoked by user code. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`__destruct()`** β€” automatically called when an object is destroyed OR when the script finishes execution. [S1] - **Opposite of `__construct()`** β€” fires at teardown instead of creation. [S1] - **No arguments** β€” unlike the constructor, `__destruct()` takes no parameters. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Constructor + destructor pair: `class Fruit { public $name; public $color; function __construct($name, $color) { $this->name = $name; $this->color = $color; } function __destruct() { echo "Name: " . $this->name . ". Color: " . $this->color .".
"; } } $apple = new Fruit('Apple', 'Red'); $banana = new Fruit('Banana', 'Yellow');` β€” the destructor for each object fires automatically at script end, printing both fruits' details even though `__destruct()` was never explicitly called. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ†ŒμŠ€μ—μ„œ λͺ¨μˆœλ˜λŠ” μ •λ³΄λŠ” λ°œκ²¬λ˜μ§€ μ•ŠμŒ. ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” μƒμ„±μž/μ†Œλ©Έμž 쌍이 μ½”λ“œ 양을 μ€„μ΄λŠ” 데 μœ μš©ν•˜λ‹€λŠ” 점이 팁으둜 κ°•μ‘°λœλ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Destructor firing automatically at script end (PHP): ```php class Fruit { public $name; public $color; function __construct($name, $color) { $this->name = $name; $this->color = $color; } function __destruct() { echo "Name: " . $this->name . ". Color: " . $this->color .".
"; } } $apple = new Fruit('Apple', 'Red'); // __destruct() runs automatically at script end ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[PHP Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[PHP OOP Constructor]], [[PHP OOP Access Modifiers]] - **μ°Έμ‘° λ§₯락:** μƒμ„±μžμ˜ λ°˜λŒ€ κ°œλ…(μ†Œλ©Έ) β€” μ ‘κ·Ό μ œμ–΄μž(Access Modifiers) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” PHP OOP - Destructor Method β€” https://www.w3schools.com/php/php_oop_destructor.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "PHP OOP Destructor Method" page (Astra wiki-curation, P-Reinforce v3.1 format).