1cfd3bbb56
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고, Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
4.6 KiB
4.6 KiB
id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
| id | title | category | status | verification_status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | created_at | updated_at | review_reason | merge_history | tags | raw_sources | applied_in | github_commit | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| php-oop-inheritance | PHP OOP Inheritance | Programming_Language | draft | conceptual |
|
B | 0.9 | 2026-07-04 | 2026-07-04 |
|
|
PHP OOP Inheritance
🎯 한 줄 통찰 (One-line insight)
Calling a protected method from OUTSIDE the class fails, but calling that SAME protected method from WITHIN a subclass's own method (via $this->intro()) succeeds — the exact rule from access modifiers applies identically to methods, and the source proves it with a direct pass/fail comparison of the two call sites. [S1]
🧠 핵심 개념 (Core concepts)
extends— inherits public and protected properties/methods from a parent class. [S1]- Private members are NOT inherited — a child class cannot access a parent's private methods/properties at all. [S1]
- Method overriding — redefining a method with the same name in the child class replaces the parent's version. [S1]
finalon a class — prevents any class from extending it. [S1]finalon a method — prevents child classes from overriding that specific method. [S1]
📖 세부 내용 (Details)
- Basic inheritance:
class Fruit { public $name; public $color; public function __construct($name, $color) {...} public function intro() {...} } class Strawberry extends Fruit { public function message() {...} } $strawberry = new Strawberry("Strawberry", "red"); $strawberry->intro(); $strawberry->message();— Strawberry uses Fruit's constructor/intro plus its own message(). [S1] - Protected method fails from outside:
$strawberry->intro(); // ERROR if intro() is protected. [S1] - Protected method works from inside a child method:
public function message() { $this->intro(); }— calling$this->intro()from withinmessage()succeeds. [S1] - Overriding: child class
Strawberryredefines__construct()andintro()with the same names, completely replacing the parent's versions (adding a$weightproperty along the way). [S1] finalprevents inheritance:final class Fruit {...} class Strawberry extends Fruit {...} // error. [S1]finalprevents method override:class Fruit { final public function intro() {...} } class Strawberry extends Fruit { public function intro() {...} // error }. [S1]
⚖️ 모순 및 업데이트 (Contradictions & updates)
- protected 메서드 호출 위치에 따른 성패: 클래스 외부에서 호출하면 에러, 파생 클래스 내부 메서드에서 $this로 호출하면 성공한다는 점이 두 대비 예제로 직접 증명됨. [S1]
🛠️ 적용 사례 (Applied in summary)
현재 발견된 실제 적용 사례가 없습니다 — Strawberry가 Fruit의 생성자/메서드를 재정의(override)하며 weight 속성을 추가하는 것이 실전 오버라이딩의 대표 사례다. [S1]
💻 코드 패턴 (Code patterns)
Overriding a parent's constructor and method (PHP):
class Fruit {
public $name;
public $color;
public function __construct($name, $color) { $this->name = $name; $this->color = $color; }
public function intro() { echo "The fruit is $this->name and the color is $this->color."; }
}
class Strawberry extends Fruit {
public $weight;
public function __construct($name, $color, $weight) {
$this->name = $name; $this->color = $color; $this->weight = $weight;
}
public function intro() {
echo "A $this->name is $this->color, and the weight is $this->weight gram.";
}
}
✅ 검증 상태 및 신뢰도
- 상태: draft
- 검증 단계: conceptual
- 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
- 신뢰 점수: 0.90
- 중복 검사 결과: 신규 생성 (New discovery)
🔗 지식 그래프 (Knowledge Graph)
- 상위/루트: PHP Tutorial
- 관련 개념: PHP OOP Access Modifiers, PHP OOP Constants, PHP OOP Classes Abstract
- 참조 맥락: 클래스 상속과 메서드 오버라이딩 — 클래스 상수(Constants) 챕터로 이어짐.
📚 출처 (Sources)
- [S1] W3Schools — PHP OOP - Inheritance — https://www.w3schools.com/php/php_oop_inheritance.asp
📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "PHP OOP Inheritance" page (Astra wiki-curation, P-Reinforce v3.1 format).