title: PHP: initialization of object properties when declaring vs when instantiating
body: <p>Consider these classes:</p>
  
  <pre><code>class Test_A {
  
      protected $value;
  
      public function __construct() {
          $this-&gt;value = null;
      }
  
  }
  
  class Test_B {
  
      protected $value = null;
  
      public function __construct() {
  
      }
  
  }
  </code></pre>
  
  <p>I would like to know which one is considered best practice for initializing object properties and why.</p>
  
  <p>Both are syntactically correct and according to PHP manual, a property can be initialized when declared only if the value is not depending on any calculation (protected $a = a + b;). If it does depend on some calculation or runtime value, it should be initialized within the class constructor.</p>
  
  <p><strong>Ref:</strong> <a href="http://www.php.net/manual/en/language.oop5.properties.php" rel="nofollow">http://www.php.net/manual/en/language.oop5.properties.php</a> (see Example #1)</p>
  
  <p>Keeping that in mind, is it a good practice to always initialize properties when declaring unless they actually need to be calculated?</p>