PHP Passing an object through a class?
<p>After restructuring my entire class layout, I'm still having trouble using multiple class instances.</p>

<pre><code>class User {
    public $variable;
    public function getUser() {
        $this-&gt;variable = 'It works!';
        return 'bob';
    }
}

class Base {}
class One extends Base {
    public function test() {
        print_r($User-&gt;variable); // Want it to print 'It works!'
    }
}

$User = new User();
$username = $User-&gt;getUser();
if($username === 'bob') {
    $One = new One();
    $One-&gt;test(); // prints "Notice: Undefined property: One::$variable
}
</code></pre>

<p>What the above code does: The class <code>User</code> gets the username. If the username is <code>bob</code>, it will create an object <code>one</code> and try to print the variable from class <code>User</code>. In my real code, <code>User</code> is extremely intricate and passing a bunch of things with <code>__construct</code> just isn't what I'm looking for.</p>

<p>I think the solution (<em>which is why I titled this question as so</em>) would be to create a new class <code>User</code> within class <code>Base</code> 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.</p>
