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