title: PHP5- instanceof/is_a failure?
body: <p>I've got this code in PHP5</p>
  
  <pre><code>&lt;?php
  function debug_log($log) {
      echo $log;
  }
  // Supporting classes
  class Tag {
      private $id;
      private $name;
      private $tagname;
      private $extras;
      public function __construct($tag) {
          $this-&gt;id = 0; // Set to non-zero if you want an id
          $this-&gt;name = ''; // Set to non-empty for a name
          $this-&gt;tagname = $tag; // This is what tag, e.g. select/html/head
          $this-&gt;extras = ''; // If we need anything extra that isn't covered
      }
      protected function OpenTag() {
          debug_log('Tag::OpenTag()');
          $html = '&lt;' . $this-&gt;tagname;
          if ($this-&gt;id != 0) {
              $html .= 'id = ' . $this-&gt;id;
          }
          if ($this-&gt;name != '') {
              $html .= 'name = ' . $this-&gt;name;
          }
          if ($this-&gt;extras != '') {
              $html .= ' ' . $this-&gt;extra;
          }
          $html .= '&gt;';
          echo $html;
      }
      protected function CloseTag() {
          debug_log('Tag::CloseTag()');
          $html = '&lt;/' . $this-&gt;tagname . '&gt;';
          echo $html;
      }
      public function ID($new_id) {
          $this-&gt;id = $new_id;
          return $this;
      }
      public function Name($new_name) {
          $this-&gt;name = $new_name;
          return $this;
      }
      public function Extras($newextras) {
          $this-&gt;extras = $newextras;
          return $this;
      }
      public function Emit() {
          Tag::OpenTag();
          Tag::CloseTag();
      }
  }
  // Unfortunately, totally necessary.
  function MakeTag($arg) {
      return new Tag($arg);
  }
  
  class ContentTag extends Tag {
      private $tags;
      public function __construct($tagname) {
          parent::__construct($tagname);
          $this-&gt;tags = array();
      }
      public function AddTag($tag) {
          array_push($this-&gt;tags, $tag);
          return $tag;
      }
      public function Emit() {
          debug_log('In ContentTag::Emit()');
          Tag::OpenTag();
          debug_log('Emitting ' . count($this-&gt;tags) . ' tags.');
          for($i = 0; $i &lt; count($this-&gt;tags); $i++) {
              if (is_a($this-&gt;tags[i], "Tag")) {
                  echo 'Emitting a tag - ';
                  $this-&gt;tags[i]-&gt;Emit();
              } else {
                  echo 'Not emitting a tag of type '. get_class($this-&gt;tags[i]);
                  echo (string)$this-&gt;tags[i];
              }
          }
          Tag::CloseTag();
      }
  }
  function MakeContentTag($arg) {
      return new ContentTag($arg);
  }
  class Listbox extends Tag {
      private $options;
      public function __construct() {
          parent::__construct('select');
          $this-&gt;options = array();
          $this-&gt;name = '';
      }
      public function AddOption($name) {
          array_push($this-&gt;options, $name);
      }
      public function SetName($new_name) {
          $this-&gt;name = $new_name;
      }
      public function Emit() {
          OpenTag();
          for($i = 0; $i &lt; sizeof($this-&gt;options); $i++) {
              $innerHTML = $innerHTML . '&lt;option&gt;' . $options[i] . '&lt;/option&gt;';
          }        
          echo $innerHTML;
          CloseTag();
      }
  }
  class Title extends Tag {
      private $title;
      public function __construct() {
          parent::__construct('title');
      }
      public function SetTitle($newtitle) {
          $this-&gt;title = $newtitle;
      }
      public function Emit() {
          OpenTag();
          echo $this-&gt;title;
          CloseTag();
      }
  }
  class Link extends Tag {
      private $href;
      private $rel;
      private $type;
      private function AddExtras() {
          Tag::Extras('href=' . $href . ' rel=' . $rel . ' type=' . $type);      
      }
      public function __construct($ahref, $arel, $atype) {
          parent::__construct('link');
          $this-&gt;href = $ahref;
          $this-&gt;rel = $arel;
          $this-&gt;type = $atype;
          $this-&gt;AddExtras();
      }
      public function Href() {
          return $this-&gt;href;
      }
      public function Rel() {
          return $this-&gt;rel;
      }
      public function Type() {
          return $this-&gt;type;
      }
      public function SetType($atype) {
          $this-&gt;type = $atype;
          $this-&gt;AddExtras();
          return $this;
      }
      public function SetHref($ahref) {
          $this-&gt;href = $ahref;
          $this-&gt;AddExtras();
          return $this;
      }
      public function SetRel($arel) {
          $this-&gt;rel = $arel;
          $this-&gt;AddExtras();
          return $this;
      }
  
  }
  function MakeLink($a, $b, $c) {
      return new Link($a, $b, $c);
  }
  class Img extends Tag {
      public function __construct($src, $alt) {
          parent::__construct('img');
          Tag::Extras('src=' . $src . ' alt=' . $alt);
      }
  }
  class DOM extends ContentTag {
      private $body;
      private $head;
      public function __construct() {
          parent::__construct('html');
          Tag::Extras('xmlns="http://www.w3.org/1999/xhtml"');
          $this-&gt;head = new ContentTag('head');
          $this-&gt;body = new ContentTag('body');
          $this-&gt;AddTag($this-&gt;head);
          $this-&gt;AddTag($this-&gt;body);
          $this-&gt;head-&gt;AddTag(MakeTag('meta')-&gt;Extras('http-equiv="Content-Type" content="text/html; charset=utf-8"'));
      }
      public function Head() {
          return $this-&gt;head;
      }
      public function Body() {
          return $this-&gt;head;
      }
      public function Emit() {
          echo '&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;';
          ContentTag::Emit();
      }
  }
  
  // top.php
  $pagediv = 0;
  $view = new DOM();
  $view-&gt;Head()-&gt;AddTag(MakeLink('css/style.css', 'stylesheet', 'text/css'));
  $view-&gt;Head()-&gt;AddTag(MakeLink('favicon.ico', 'icon', 'image/x-icon'));
  $view-&gt;Head()-&gt;AddTag(MakeContentTag('div')-&gt;ID('top_grad'));
  $div = $view-&gt;Body()-&gt;AddTag(MakeContentTag('div')-&gt;Extras('align="center"'));
  $topdiv = $div-&gt;AddTag(MakeContentTag('div')-&gt;ID('top'));
  $topdiv-&gt;AddTag(MakeContentTag('div')-&gt;ID('logo'))-&gt;AddTag(new Img('images/loughborough-logo.png', 'Loughborough University'));
  $topdiv-&gt;AddTag(MakeContentTag('div')-&gt;ID('title'))-&gt;AddTag('TimeTable System');
  $topdiv-&gt;AddTag(MakeContentTag('div')-&gt;ID('roundnumber')-&gt;Extras('align="right"'))-&gt;AddTag('Welcome ' . $_SESSION['username'] . '&lt;/br&gt;' . 'Round Number: 1');
  $page = $topdiv-&gt;AddTag(MakeContentTag('div')-&gt;ID('page'));
  $view-&gt;Emit();
  ?&gt;
  </code></pre>
  
  <p>It's quite a bit of code, but frankly, I'm just not sure what to post. The ContentTag::Emit method is failing. Specifically, variables inside <code>$tags</code> are failing the <code>instanceof Tag</code> check, even though they are of type <code>ContentTag</code>, and <code>get_class</code> confirms this. But if I remove the check and Emit anyway, then it says that Emit does not exist- even though I just confirmed using <code>get_class</code> that those variables are of type ContentTag. The <em>quantity</em> is correct, so I'm pretty sure that all the preceeding code is correct too. I've also changed between <code>is_a</code> and <code>instanceof</code> and they both exhibit the same problems.</p>