title: Approach class constant through class member variable
body: <p>I have trouble accessing a constant of a class via the object operator(<code>-&gt;</code>).</p>
  
  <p>I have these 2 classes:</p>
  
  <pre><code>class withConstant {
      const MY_CONSTANT = 5;
  }
  class usingConstant {
      public $class = null;
      function __construct() {
          $this-&gt;class = new withConstant();
      }
  }
  </code></pre>
  
  <p>When I do this:</p>
  
  <pre><code>$myClass = new usingConstant();
  echo $myClass-&gt;class::MY_CONSTANT;
  </code></pre>
  
  <p>I get an error <code>Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)</code>. However, I can get around it with this:</p>
  
  <pre><code>$myClass = new usingConstant();
  $myClass = &amp;$myClass-&gt;class;
  echo $myClass::MY_CONSTANT;
  </code></pre>
  
  <p>I prefer to access the constant without assigning the member variable to another variable first.</p>