title: Why can't you override parent variable with constant value in child class? (PHP)
body: <p>I have a class first where <code>$name</code> is set to 'bob'. In the child class, I set <code>$name</code> to 'Karen' but it doesn't work.</p>
  
  <p>In my echo statements, the 1st one says "bob" instead of 'Karen'. The second one, using a child class method, works though.</p>
  
  <p>Why is this behavior?</p>
  
  <pre><code>class First {
  
      public $name;
  
      public function __construct() {
  
          $this-&gt;name = 'bob';
      }
  }
  
  class Third extends First {
  
      public $name = 'Karen';
      public function set_name ($name) {
          $this-&gt;name = $name;
      }
  }
  
  $instance_of_third = new Third;
  $third_name = $instance_of_third-&gt;name;
  
  echo "&lt;br /&gt;We're looking for Karen: $third_name&lt;br /&gt;";
  // $third_name here is 'bob' from parent class
  
  $instance_of_third-&gt;set_name("Karen");
  $third_name = $instance_of_third-&gt;name;
  // $third_name here is 'Karen' only after using set_name()
  echo "&lt;br /&gt;We're looking for Karen: $third_name&lt;br /&gt;";
  </code></pre>
  
  <p>EDIT: I added 2 lines showing what the output was exactly.</p>
  
  <p>Even though <code>$name</code> is explicitly set to 'Karen' in child class, it shows as 'bob' unless the <code>set_name()</code> function is used to change it.</p>