After restructuring my entire class layout, I'm still having trouble using multiple class instances.
class User {
public $variable;
public function getUser() {
$this->variable = 'It works!';
return 'bob';
}
}
class Base {}
class One extends Base {
public function test() {
print_r($User->variable); // Want it to print 'It works!'
}
}
$User = new User();
$username = $User->getUser();
if($username === 'bob') {
$One = new One();
$One->test(); // prints "Notice: Undefined property: One::$variable
}
What the above code does: The class User gets the username. If the username is bob, it will create an object one and try to print the variable from class User. In my real code, User is extremely intricate and passing a bunch of things with __construct just isn't what I'm looking for.
I think the solution (which is why I titled this question as so) would be to create a new class User within class Base but I just can't wrap my head around having to create a whole new object and re-initiate everything just to get the username.
$thismeans.