I quickly looked through some of these questions, but none of the answers touched on the problem I am having.
I have two files. product.php and index.php . Product.php defines the class of the product, and I just use index.php as the page for outputting the variables. Ideally, this will be used to output objects from different classes in the future.
product.php
class Product{
public $var = "a default value";
public function __construct($var){
$var = $var;
}
public function displayVar(){
echo $this->var;
}
}
index.php (all enclosed in php tags)
require_once("product.php");
$product = new Product();
echo $product->var;
I tried using various file inclusion methods (require, include, include_once). I am not sure if this is a problem.
The problem I get is $ product-> var, which is not output. Instead, I get the following error:
Notice: Undefined property: Product::$var in C:\xampp\htdocs\FurnitureWebsite\index.php on line 21
, undefined. PHP , .
: , index.php, . , - , , , .