View Full Version : Help with class and variables

08-14-2007, 05:39 PM
Hy guys

I'm php newbie, looking for some guidance with php oop. I'm trying to get some variables into class but getting this error

Parse error: parse error, unexpected T_VARIABLE in D:\www\Apache2\htdocs\test.php on line 7

This is the full code

$variable = "my variable";

class phpClass {
public $main = $variable;

public function main() {

echo $this->main;



$mainis = new phpClass;



Thanks for your help

08-14-2007, 06:38 PM
$variable is not within the scope of the class, e.g. it does not know it exists, you would normally set a default value

public $main='';

and populate $main via a setter or in the constructor

public function main($var){

08-14-2007, 08:50 PM
So that is not how it's done.

Thanks for explaining the situation @oop newbie