I recently started with PHP Object Oriented and I cannot seem to get this done. In a method I declare a property which I want to use in another method, but I get an error: Undefined property: Database::$test.
class Database {
public function connect() {
$connection = 'hoi';
}
public function disconnect() {
echo $this->connection;
}
}
$db = new Database();
$db->connect();
$db->disconnect();
Again, I’m new at OOP. I tried using global with the scope of a function in mind which would make sense in a regular function, but I just get another error when I use that.
is simply defining a local variable, not assigning as a property in the object. It should be: