Jump to content

Undefined variable notice in class?


ZachMEdwards

Recommended Posts

I'm new to PHP classes. Can someone show me why this is throwing a notice / fatal error? And how do I fix it?

 

test.php:

<?PHP
class testVariable {
	private $test = 'testing';

	public function __construct() {
		echo $this->$test;
	}

}
?>

index.php:

<?PHP
require_once 'test.php';
$test = new testVariable();
?>

 

Notice: Undefined variable: test in C:\www\test.php on line 6

 

Fatal error: Cannot access empty property in C:\www\test.php on line 6

Link to comment
https://forums.phpfreaks.com/topic/203235-undefined-variable-notice-in-class/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.