I am new to PHP, I am having problems transferring the class definition from my "main" page and into the include file.
Suppose I have main.php, with the content below. It works great:
<?php
class SimpleClass
{
public $var = 'a def value';
public function displayVar() {
echo $this->var;
}
}
?>
<html>
<h1>blah blah blah</h1>
</html>
But now suppose I try to remove the class definition and put it in a separate file, so main.htm now looks like this:
<?php
include("classdef.php");
?>
<html>
<h1>blah blah blah</h1>
</html>
and classdef.php:
<?php
class SimpleClass
{
public $var = 'a def value';
public function displayVar() {
echo $this->var;
}
?>
Then, when I view my main.php file, it displays as
var; } } ?>
blah blah blah
As if the character >in is $this->varinterpreted as closing PHP. I am having trouble finding this because I don't know how the statement is called ->.
This is PHP 5.3.3 on Apache 2.2 on Windows.