Files
2nd/10_Wiki/Dev/Topic_PHP/PHP_OOP_Access_Modifiers.md
T
Antigravity Agent 1cfd3bbb56 docs(10_Wiki): 위키 구조 정리 — 언어 튜토리얼 카테고리 폴더 제거 + 신규 자산 동기화
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고,
Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
2026-07-05 00:10:59 +09:00

3.8 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-access-modifiers PHP OOP Access Modifiers Programming_Language draft conceptual
public private protected
PHP 접근 제어자
B 0.9 2026-07-04 2026-07-04
php
programming
w3schools
oop
access-modifiers
https://www.w3schools.com/php/php_oop_access_modifiers.asp

PHP OOP Access Modifiers

🎯 한 줄 통찰 (One-line insight)

protected occupies a middle ground invisible from direct outside access, YET fully usable inside a subclass via its own method — a child class can't do $apple->name directly, but a method it defines (like getType()) CAN read $this->name because it executes inside the class hierarchy, not from outside it. [S1]

🧠 핵심 개념 (Core concepts)

  • public (default if unspecified) — accessible from anywhere. [S1]
  • protected — accessible within the class AND by derived (child) classes; NOT accessible directly from outside. [S1]
  • private — accessible ONLY within the exact class where defined; not even child classes can access it directly. [S1]

📖 세부 내용 (Details)

  • Public (works from outside): class Fruit { public $name; ... } $apple = new Fruit(); $apple->name = "Apple"; // OK. [S1]
  • Private (fails from outside): class Fruit { private $name; ... } $apple->name = "Apple"; // Error. [S1]
  • Protected (fails from outside): class Fruit { protected $name; ... } $apple->name = "Apple"; // Error. [S1]
  • Protected accessible via a child class's own method: class Fruit { protected $name; public function setType($name) { $this->name = $name; } } class Apple extends Fruit { public function getType() { echo "Name: " . $this->name . "."; } } $apple = new Apple(); $apple->setType("Apple"); echo $apple->getType(); // works — accessed via a method, not directly. [S1]

⚖️ 모순 및 업데이트 (Contradictions & updates)

  • protected의 이중적 접근성: 외부에서 직접 접근($apple->name)은 불가하지만, 자식 클래스가 정의한 메서드 내부($this->name)에서는 접근 가능하다는 점이 예제로 명확히 대비됨. [S1]

🛠️ 적용 사례 (Applied in summary)

현재 발견된 실제 적용 사례가 없습니다 — Fruit→Apple 상속 구조에서 protected 속성에 자식 클래스 메서드로 접근하는 것이 캡슐화의 대표 실전 사례다. [S1]

💻 코드 패턴 (Code patterns)

Protected property accessible via a child class's method, not directly (PHP):

class Fruit {
    protected $name;
    public function setType($name) { $this->name = $name; }
}
class Apple extends Fruit {
    public function getType() { echo "Name: " . $this->name . "."; }
}
$apple = new Apple();
$apple->setType("Apple");
echo $apple->getType(); // works
// echo $apple->name; // Error: cannot access protected property directly

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.90
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-07-04: Initial draft synthesized from the W3Schools "PHP OOP Access Modifiers" page (Astra wiki-curation, P-Reinforce v3.1 format).