--- id: php-oop-interfaces title: "PHP OOP Interfaces" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["implements keyword", "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", "oop", "interfaces"] raw_sources: ["https://www.w3schools.com/php/php_oop_interfaces.asp"] applied_in: [] github_commit: "" --- # [[PHP OOP Interfaces]] ## 🎯 한 줄 통찰 (One-line insight) A class can `implements` an interface WHILE ALSO `extends`-ing another class simultaneously — this is the key structural advantage over abstract classes explicitly called out in the comparison table, since PHP only allows single class inheritance but interfaces don't consume that one inheritance slot. [S1] ## 🧠 핵심 개념 (Core concepts) - **`interface`** — defines a set of public methods a class MUST implement, without specifying HOW. [S1] - **`implements`** — the keyword a class uses to fulfill an interface's contract; must implement ALL declared methods. [S1] - **Interface vs. abstract class differences** — interfaces cannot have properties (abstract classes can); ALL interface methods must be public and are implicitly abstract (no `abstract` keyword needed); a class can implement an interface while still extending another class. [S1] - **Polymorphism via interfaces** — multiple classes implementing the same interface can be used interchangeably. [S1] ## 📖 세부 내용 (Details) - Basic interface: `interface Animal { public function makeSound(); } class Cat implements Animal { public function makeSound() { echo "Meow"; } } class Dog implements Animal { public function makeSound() { echo "Woff"; } }`. [S1] - Multi-method interface: `interface Animal { public function fromFamily(); public function makeSound(); }` — both Cat and Dog must implement BOTH methods. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) - **인터페이스 vs 추상 클래스의 핵심 차이**: 인터페이스는 속성을 가질 수 없고 모든 메서드가 public+abstract이며, 클래스 상속과 동시에 구현 가능하다는 점이 표로 명확히 대비됨. [S1] ## 🛠️ 적용 사례 (Applied in summary) 현재 발견된 실제 적용 사례가 없습니다 — Cat/Dog가 동일한 Animal 인터페이스를 구현해 일관된 방식으로 다룰 수 있는 것(다형성)이 실전 활용의 대표 사례다. [S1] ## 💻 코드 패턴 (Code patterns) Two classes implementing the same interface uniformly (PHP): ```php interface Animal { public function fromFamily(); public function makeSound(); } class Cat implements Animal { public function fromFamily() { echo "From family: Felidae.
"; } public function makeSound() { echo "Sound: Meow."; } } class Dog implements Animal { public function fromFamily() { echo "From family: Canidae.
"; } public function makeSound() { echo "Sound: Woff."; } } ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.90 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[PHP Tutorial]] - **관련 개념:** [[PHP OOP Classes Abstract]], [[PHP OOP Traits]] - **참조 맥락:** 다형성을 위한 메서드 계약 — 트레이트(Traits) 챕터로 이어짐. ## 📚 출처 (Sources) - [S1] W3Schools — PHP OOP - Interfaces — https://www.w3schools.com/php/php_oop_interfaces.asp ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "PHP OOP Interfaces" page (Astra wiki-curation, P-Reinforce v3.1 format).