title: Access class constant and static method from string
body: <p>I have a string containing the class name and I wish to get a constant and call a (static) method from that class.</p>
  
  <pre><code>&lt;?php
  $myclass = 'b'; // My class I wish to use
  
  $x = new x($myclass); // Create an instance of x
  $response = $x-&gt;runMethod(); // Call "runMethod" which calls my desired method
  
  // This is my class I use to access the other classes
  class x {
      private $myclass = NULL;
  
      public function __construct ( $myclass ) {
          if(is_string($myclass)) {
              // Assuming the input has a valid class name
              $this-&gt;myclass = $myclass;
          }
      }
  
      public function runMethod() {
          // Get the selected constant here
          print $this-&gt;myclass::CONSTANT;
  
          // Call the selected method here
          return $this-&gt;myclass::method('input string');
      }
  }
  
  
  // These are my class(es) I want to access
  abstract class a {
      const CONSTANT = 'this is my constant';
  
      public static function method ( $str ) {
          return $str;
      }
  }
  
  class b extends a {
      const CONSTANT = 'this is my new constant';
  
      public static function method ( $str ) {
          return 'this is my method, and this is my string: '. $str;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>As I expected (more or less), using <code>$variable::CONSTANT</code> or <code>$variable::method();</code> doesn't work.</p>
  
  <p>Before asking what I have tried; I've tried so many things I basically forgot.</p>
  
  <p>What's the best approach to do this? Thanks in advance.</p>