title: Can I call a static function from a trait outside of a class?
body: <p>Consider the situation where there are multiple classes that all need to have access to the configuration storage mechanism, but cannot be extended from a base class because of the architectuur of the framework.
  In addition to that I wanted to keep the storage mechanism flexible (be able to switch storage backend later).</p>
  
  <p>I felt it would make sense to create a trait which does the actual saving and use those functions inside all classes (for the example I use <code>$_SESSION</code> as storage system):</p>
  
  <pre><code>trait MyTrait {
  
    function setting_enabled() {
      return !empty($_SESSION['setting']) ? TRUE : FALSE;
    }
  
    function enable_setting() {
      $_SESSION['setting'] = TRUE;
    }
  
    function disable_setting() {
      $_SESSION['setting'] = FALSE;
    }
  
  }
  </code></pre>
  
  <p>This works great from classes. There is however also one file that is not a class, but is just plain PHP, for which I also need to know if the setting is enabled. </p>
  
  <p>I have tried declaring the function as <code>static</code>:</p>
  
  <pre><code>trait MyTrait {
  
    static function setting_enabled() { // Declared as static function
      return !empty($_SESSION['setting']) ? TRUE : FALSE;
    }
  
    ...
  }
  </code></pre>
  
  <p>And then call the static function from the trait, which worked fine.</p>
  
  <pre><code>if (MyTrait::setting_enabled()) {
    ...
  }
  </code></pre>
  
  <p>It however feels not entirely right. On the other hand, creating a new empty class that uses the trait and instantiating that to obtain the value seems like a lot of overhead. </p>
  
  <p>Am I allowed to do this (as of PHP 5.6, but also considering the future with PHP 7.x)?</p>