php - PHP5- instanceof/is_a failure? -


i've got code in php5

<?php function debug_log($log) {     echo $log; } // supporting classes class tag {     private $id;     private $name;     private $tagname;     private $extras;     public function __construct($tag) {         $this->id = 0; // set non-zero if want id         $this->name = ''; // set non-empty name         $this->tagname = $tag; // tag, e.g. select/html/head         $this->extras = ''; // if need isn't covered     }     protected function opentag() {         debug_log('tag::opentag()');         $html = '<' . $this->tagname;         if ($this->id != 0) {             $html .= 'id = ' . $this->id;         }         if ($this->name != '') {             $html .= 'name = ' . $this->name;         }         if ($this->extras != '') {             $html .= ' ' . $this->extra;         }         $html .= '>';         echo $html;     }     protected function closetag() {         debug_log('tag::closetag()');         $html = '</' . $this->tagname . '>';         echo $html;     }     public function id($new_id) {         $this->id = $new_id;         return $this;     }     public function name($new_name) {         $this->name = $new_name;         return $this;     }     public function extras($newextras) {         $this->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->tags = array();     }     public function addtag($tag) {         array_push($this->tags, $tag);         return $tag;     }     public function emit() {         debug_log('in contenttag::emit()');         tag::opentag();         debug_log('emitting ' . count($this->tags) . ' tags.');         for($i = 0; $i < count($this->tags); $i++) {             if (is_a($this->tags[i], "tag")) {                 echo 'emitting tag - ';                 $this->tags[i]->emit();             } else {                 echo 'not emitting tag of type '. get_class($this->tags[i]);                 echo (string)$this->tags[i];             }         }         tag::closetag();     } } function makecontenttag($arg) {     return new contenttag($arg); } class listbox extends tag {     private $options;     public function __construct() {         parent::__construct('select');         $this->options = array();         $this->name = '';     }     public function addoption($name) {         array_push($this->options, $name);     }     public function setname($new_name) {         $this->name = $new_name;     }     public function emit() {         opentag();         for($i = 0; $i < sizeof($this->options); $i++) {             $innerhtml = $innerhtml . '<option>' . $options[i] . '</option>';         }                 echo $innerhtml;         closetag();     } } class title extends tag {     private $title;     public function __construct() {         parent::__construct('title');     }     public function settitle($newtitle) {         $this->title = $newtitle;     }     public function emit() {         opentag();         echo $this->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->href = $ahref;         $this->rel = $arel;         $this->type = $atype;         $this->addextras();     }     public function href() {         return $this->href;     }     public function rel() {         return $this->rel;     }     public function type() {         return $this->type;     }     public function settype($atype) {         $this->type = $atype;         $this->addextras();         return $this;     }     public function sethref($ahref) {         $this->href = $ahref;         $this->addextras();         return $this;     }     public function setrel($arel) {         $this->rel = $arel;         $this->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->head = new contenttag('head');         $this->body = new contenttag('body');         $this->addtag($this->head);         $this->addtag($this->body);         $this->head->addtag(maketag('meta')->extras('http-equiv="content-type" content="text/html; charset=utf-8"'));     }     public function head() {         return $this->head;     }     public function body() {         return $this->head;     }     public function emit() {         echo '<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">';         contenttag::emit();     } }  // top.php $pagediv = 0; $view = new dom(); $view->head()->addtag(makelink('css/style.css', 'stylesheet', 'text/css')); $view->head()->addtag(makelink('favicon.ico', 'icon', 'image/x-icon')); $view->head()->addtag(makecontenttag('div')->id('top_grad')); $div = $view->body()->addtag(makecontenttag('div')->extras('align="center"')); $topdiv = $div->addtag(makecontenttag('div')->id('top')); $topdiv->addtag(makecontenttag('div')->id('logo'))->addtag(new img('images/loughborough-logo.png', 'loughborough university')); $topdiv->addtag(makecontenttag('div')->id('title'))->addtag('timetable system'); $topdiv->addtag(makecontenttag('div')->id('roundnumber')->extras('align="right"'))->addtag('welcome ' . $_session['username'] . '</br>' . 'round number: 1'); $page = $topdiv->addtag(makecontenttag('div')->id('page')); $view->emit(); ?> 

it's quite bit of code, frankly, i'm not sure post. contenttag::emit method failing. specifically, variables inside $tags failing instanceof tag check, though of type contenttag, , get_class confirms this. if remove check , emit anyway, says emit not exist- though confirmed using get_class variables of type contenttag. quantity correct, i'm pretty sure preceeding code correct too. i've changed between is_a , instanceof , both exhibit same problems.

the issue have forgetting $ variable tokens on increment value i in loops:

php notice:  undefined index:  in dom.php on line 74 php notice:  use of undefined constant - assumed 'i' in dom.php on line 78 php notice:  undefined index:  in dom.php on line 78 not emitting tag of type php notice:  use of undefined constant - assumed 'i' in dom.php on line 79 php notice:  undefined index:  in /dom.php on line 79 php notice:  use of undefined constant - assumed 'i' dom.php on line 74 php notice:  undefined index:  in dom.php on line 74 php notice:  use of undefined constant - assumed 'i' in dom.php on line 78 php notice:  undefined index:  in dom.php on line 78 not emitting tag of type php notice:  use of undefined constant - assumed 'i' in dom.php on line 79 php notice:  undefined index:  in dom.php on line 79 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -