OOP를 배우려는 중이며 몇 가지 질문이 있습니다. 나는 뒤에 오는 포스트뿐만 아니라 PHP Objects, Patterns, and Practice에있는 처음 몇 장을 읽었다; Nettuts+, PHP Freaks 및 PHPRO.Noob PHP OOP Questions : 생성자와 중괄호
- 하위 클래스에서 생성자는 부모 클래스에 이미있는 변수를 나열해야합니까?
- 메소드 또는 다른 장소에서 속성을 검색 할 때 내 값을 중괄호 (예 : {$ this-> id})로 묶어야하는 이유는 무엇입니까?
- 누군가가 (내가 뭘 잘못하고 있는지와 같은) 조언이 있다면, 나는 어떤 비판도 할 수 있습니다.
class Element { public $tag; public $id; function __construct($tag, $id) { $this->tag = $tag; $this->id = $id; } public function getAttributes() { return "id='{$this->id}'"; } } class NormalElement extends Element { public $text; function __construct($tag, $id, $text) { parent::__construct($tag, $id); $this->text = $text; } public function getElement() { return "<{$this->tag}>{$this->text}</{$this->tag}>"; } } class VoidElement extends Element { function __construct($tag, $id) { parent::__construct($tag, $id); } public function getElement() { return "<{$this->tag} " . parent::getAttributes() . " />"; } }
와우 ... 그게 가장 이상한 경험이었습니다. 그래서 게시물의 형식을 지정하려고했는데 ... 그 순서가 정해진 목록에 관한 것이 었습니다. 작동하도록 규칙을 던져야했습니다. – prodigitalson