title: PHP trait: is there a proper way to ensure that class using a trait extends a super class which contains certain method?
body: <p>Example #2 from PHP manual <a href="http://php.net/manual/en/language.oop5.traits.php" rel="noreferrer">http://php.net/manual/en/language.oop5.traits.php</a> states</p>
  
  <pre><code>&lt;?php
  class Base {
      public function sayHello() {
          echo 'Hello ';
      }
  }
  
  trait SayWorld {
      public function sayHello() {
          parent::sayHello();
          echo 'World!';
      }
  }
  
  class MyHelloWorld extends Base {
      use SayWorld;
  }
  
  $o = new MyHelloWorld();
  $o-&gt;sayHello();
  ?&gt;
  </code></pre>
  
  <p>This is correct code, but it's not safe to use <code>parent::</code> in that context. Let's say I wrote my own 'hello world' class which does not inherit any other classes:</p>
  
  <pre><code>&lt;?php
  class MyOwnHelloWorld
  {
      use SayWorld;
  }
  ?&gt;
  </code></pre>
  
  <p>This code will not produce any errors until I call the <code>sayHello()</code> method. This is bad.</p>
  
  <p>On the other hand if the trait needs to use a certain method <strong>I can write this method as abstract</strong>, and this is good as it ensures that the trait is correctly used at compile time. But this does not apply to parent classes:</p>
  
  <pre><code>&lt;?php
  trait SayWorld
  {
      public function sayHelloWorld()
      {
          $this-&gt;sayHello();
          echo 'World!';
      }
  
      public abstract function sayHello(); // compile-time safety
  
  }
  </code></pre>
  
  <p>So my question is: Is there a way to ensure (at compile time, not at runtime) that class which uses a certain trait will have <code>parent::sayHello()</code> method?</p>