Forum Moderators: coopster

Message Too Old, No Replies

Class Inheritance Problem

         

mightymouse3062

4:01 am on Feb 5, 2010 (gmt 0)

10+ Year Member



Good Evening,
I am working on a php class script to display content and the problem I am having is inside one of the functions in the class I set a variable to something, other functions do not see that the variable exists. I am running PHP version 4.4.9.
Here is the index.php file that is calling Render.php:
<?php
require_once("./pages/Render.php");

Render::setTitle("Work");
Render::displayOutput();
?>


Here is Render.php:

<?php
class Render {

var $siteTitle;

var $additionalHeaders = null;

var $siteContent = null;

function Render(){
// Constructor
}

function setTitle($inputTitle){
$this->siteTitle = $inputTitle;
}

function addHeader($inputHeader){
$this->additionalHeaders[count($this->additionalHeaders)] = $inputHeader;
}

function addContent($inputContent, $position = 0){
$contentCount = count($this->siteContent);
if($position != 0 && $contentCount >= $position){
for($i = $contentCount - 1; $i >= $position; $i--){
$this->siteContent[$i + 1] = $this->siteContent[$i];
}
$this->siteContent[$position] = $inputContent;
} else {
$this->siteContent[$contentCount] = $inputContent;
}
}

function displayTitle(){
echo $this->siteTitle;
}

function displayHeaders(){
for($i = 0; $i < count($this->additionalHeaders); $i++){
echo $this->additionalHeaders[$i] . "\n";
}
}

function displayContent(){
for($i = 0; $i < count($this->siteContent); $i++){
echo $this->siteContent[$i] . "\n";
}
}

function displayOutput(){
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><?php Render::displayTitle(); ?></title>
<?php Render::displayHeaders(); ?>
</head>
<body>
<?php Render::displayContent(); ?>
</body>
</html>
<?php
}
}
?>


Does anyone have any suggestions on how to fix the problem I am having?

Thanks,
Mike

coopster

1:26 pm on Feb 26, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You are using the class statically [php.net].