title: How can a PHP trait know when a function has been aliased or renamed?
body: <p>I have a PHP trait thats used in many classes. Some of those classes choose to rename the trait functions. One of the methods in the trait would like to call itself. How can it call itself? How can it find out what is has been renamed to?</p>
  
  <pre><code>&lt;?php
  
  Trait TestTrait 
  {
      protected function testFunction()
      {
          // Calls TestClass function
          // instead of the trait function.
  
          $this-&gt;testFunction();
  
          // Calls TestClass function
          // instead of the trait function.
  
          static::testFunction();
  
          // Fatal error: Call to protected method 
          // TestTrait::testFunction() from context 'TestClass'
  
          TestTrait::testFunction(); # __METHOD__ 
  
          // This works but requires that
          // the trait know that the function 
          // has been renamed. How can we 
          // determine if has been renamed?
  
          $this-&gt;traitTestFunction();
      }
  }
  
  class TestClass
  {
      use TestTrait
      {
          testFunction as traitTestFunction;
      }
  
      function testFunction()
      {
          $this-&gt;traitTestFunction();
      }
  }
  
  $test = new TestClass();
  $test-&gt;testFunction();
  </code></pre>
  
  <p>Related: <a href="https://stackoverflow.com/questions/19073721/anyone-know-of-a-php-magic-constant-for-traits-redefined-name-in-a-class">Anyone know of a PHP Magic Constant for Trait&#39;s Redefined Name in a Class?</a></p>