0

Hi All,

Can anybody see my error with this following class?

im expecting it to show a blank page, but with a title, and when i view source to show the page structure.

<?php
class webpage {
	private $doctype = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">";
	private $head    = "<html><head>";
	private $title   = "</head><title>success";
	private $body    = " </title><body>";
	private $ender     = "</body></html>";
	
	private function __construct(){
		$this->doctype = $doctype;
		$this->head = $head;
		$this->title = $title;
		$this->body = $body;
		$this->ender = $end;
		}
		
		public function content(){		
			
			$page = $this->doctype;
			$page .= $this->head;
			$page .= $this->title;
			$page .= $this->body;
			$page .= $this->ender;
			return $page;
		}
	
}

//class indexPage extends webpage{
//	
//}

$thing = new webpage();
echo $thing->content();

?>
2
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by whiteyoh
0

Hi,

Ive done it on purpose this way, so i can concatenate content

0

sorry my mistake i see what you mean. This has made no difference though.

0

there seems to be something wrong with the construct. if i remove it, it works fine

0

The below code is what you want, should write as:

<?php
class webpage {
	private $doctype;
	private $head;
	private $title;
	private $body;
	private $ender;
	
	
		public function __construct() {
			$this->doctype = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">";
			$this->head = "<html><head>";
			$this->title = "<title>success";
			$this->body = " </title></head><body>";
			$this->ender = "</body></html>";
		}
		
		public function content(){		
			
			$page = $this->doctype;
			$page .= $this->head;
			$page .= $this->title;
			$page .= $this->body;
			$page .= $this->ender;
			return $page;
		}
	
}

$thing = new webpage;
echo $thing->content();


?>
0

Thanks for this it worked fine.

I hope you dont mind a related sub question.

if added an extended class, which id like to concatenate to the $body.

i hope to have a class extension for each page, which when selected will concatenate to the $body

class index extends webpage{
	
	private $content;
			
		function __construct($doctype, $head, $title, $body, $ender, $content){
		
		parent::__construct($doctype, $head, $title, $body, $ender);
		$this->content = "i am the index page";
		
		}
		
		function indexcontent(){
			
		}
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.