Hello guys!
Im coding a new project and ran into this very odd error, the output says:
Fatal error: Using $this when not in object context in C:\wamp\www\ChessRPG\inc\template.inc.php on line 23
I tried a work around, at that time it was possible to just assign the final value to the variable but more errors like this started to show up, so think I should get this cleared out before going on to redesign the whole project. I have commented above the two lines that I know show this same error:
The project is running on a PHP5 server (its actually WAMP) in case this helps...PHP Code:<?php
/**
*@author purefan
*/
class Template
{
// Attributes
// the path to the templates
var $path = "templates/";
// the file name we're fetching
var $_file = "";
// the array of changes to be applied to this fileName
var $_changes = array();
// Functions
function Template()
{}
function loadTemplate($section = "", $fn)
{
// this next line is error number 1
$filename = $this->path;
$filename.=$section.$fn;
if(file_exists($filename))
{
$fr = fopen($filename,"r");
$this->_file = fread($fh, filesize($myFile));
return true;
}
return false;
}
function setChanges($arr)
{
$this->_changes = $arr;
}
function applyChanges()
{
if($this-_file != "")
{
foreach($this->_changes as $from => $to)
{
$this->_file = str_replace("{%".$from."%}", $to, $this->_file);
}
//$this->_file = str_replace("{".$from."}", $to, $this->_file);
}
}
function prnTemplate($isReturn = false)
{
if($isReturn){
return $this->_file;
}
else
{
// this other line shows another error like before
echo $this->_file;
}
}
}
?>
Ive looked around but the obvious replies have been what the error itself suggests, that $this is being used in a non object context, but I just want to access the attribute like ive done always before, dont know why this time it isnt working...
Thanks for your time![]()


)
Reply With Quote
Bookmarks