title: Noob PHP OOP Questions: Constructors and Curly Brackets
body: <p>I'm attempting to learn OOP and have a few questions.  I've read the first few chapters in <a href="https://rads.stackoverflow.com/amzn/click/com/143022925X" rel="nofollow noreferrer" rel="nofollow noreferrer">PHP Objects, Patterns, and Practice</a>, as well as the following posts; <a href="http://net.tutsplus.com/tutorials/php/object-oriented-php-for-beginners/" rel="nofollow noreferrer">Nettuts+</a>, <a href="http://www.phpfreaks.com/tutorial/oo-php-part-1-oop-in-full-effect" rel="nofollow noreferrer">PHP Freaks</a>, and <a href="http://www.phpro.org/tutorials/Object-Oriented-Programming-with-PHP.html" rel="nofollow noreferrer">PHPRO</a>.</p>
  
  <ol>
  <li>In the child class, does the constructor have to list the variables that already exist in the parent class?</li>
  <li>When I retrieve a property in my methods (or other places), why do I need to wrap my values in curly brackets (i.e. {$this->id})?</li>
  <li>Also, if anyone has any advice (such as what I'm doing wrong), I'm open to any criticism.</li>
  </ol>
  
  <hr>
  
  <pre><code>class Element {
    public $tag;
    public $id;
  
    function __construct( $tag, $id ) {
      $this-&gt;tag = $tag;
      $this-&gt;id = $id;
    }
  
    public function getAttributes()  {
      return "id='{$this-&gt;id}'";
    }
  }
  
  
  class NormalElement extends Element {
    public $text;
  
    function __construct( $tag, $id, $text ) {
      parent::__construct( $tag, $id );
      $this-&gt;text = $text;
    }
  
    public function getElement() {
      return "&lt;{$this-&gt;tag}&gt;{$this-&gt;text}&lt;/{$this-&gt;tag}&gt;";
    }
  }
  
  class VoidElement extends Element {
  
    function __construct( $tag, $id ) {
      parent::__construct( $tag, $id );
    }
  
    public function getElement() {
      return "&lt;{$this-&gt;tag} " . parent::getAttributes() . " /&gt;";
    }
  }
  </code></pre>
  
  <p>I spent a while attempting to get my code to display correctly in this post, but it keeps breaking.</p>