I\'m very new to PHP classes so forgive me if the answer is really obvious. I\'m trying to figure out how to use a variable defined outside of a class inside of a class. Her
Try this:
$myVar = 'value'; class myClass { private $class_var; public function __construct($myVar) { $this->class_var=$myVar; } //REST OF CLASS BELOW }
When declaring the class, you will need to pass $myVar like so, $myClass = new myClass($myVar);.
$myVar
$myClass = new myClass($myVar);