title: Accessing object's properties from another class
body: <p>I'm playing around with OOP in PHP and I've got the following code:</p>
  
  <p><strong>index.php:</strong></p>
  
  <pre><code>&lt;?php
  include('user.class.php');
  include('page.class.php');
  
  $user = new User;
  $page = new Page;
  
  $page-&gt;print_username();
  ?&gt;
  </code></pre>
  
  <p><strong>user.class.php:</strong></p>
  
  <pre><code>&lt;?php
  class User {
  
      public function __construct() {
  
          $this-&gt;username = "Anna";
      }
  }
  ?&gt;
  </code></pre>
  
  <p><strong>page.class.php:</strong></p>
  
  <pre><code>&lt;?php
  class Page extends User {
  
      public function __construct() {
      }
  
      public function print_username() {
  
          echo $user-&gt;username;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>My problem occurs in the class "Page", in the print_username() function.</p>
  
  <p>How do I access the $user object's properties within this class? I am, as you can see, defining the two objects in index.php.</p>
  
  <p>Thanks in advance</p>
  
  <p>/C</p>