title: Method accessing protected property of another object of the same class
body: <p>Should an object's method be able to access a protected property of another object of the same class?</p>
  
  <p>I'm coding in PHP, and I just discovered that an object's protected property is allowed to be accessed by a method of the same class even if not of the same object.</p>
  
  <p>In the example, at first, you'll get "3" in the output - as function readOtherUser will have successfully accessed the value -, and after that a PHP fatal error will occur - as the main program will have failed accessing the same value.</p>
  
  <pre><code>&lt;?php
  
  class user
  {
  protected $property = 3;
  
  public function readOtherUser ()
  {
      $otherUser = new user ();
      print $otherUser->property;
  }
  }
  
  $user = new user ();
  
  $user->readOtherUser ();
  print $user->property;
  
  ?></code></pre>
  
  <p>Is this a PHP bug or is it the intended behaviour (and I'll have to relearn this concept… :)) (and are there references to the fact)? How is it done in other programming languages?</p>
  
  <p>Thanks!</p>