title: PHP: Class Name Constant vs string performance
body: <p>There is a feature started from php 5.5 to get class name with full namespace with magic built in <code>class</code> constant. For example</p>
  
  <pre><code>&lt;?php
  namespace Something\Obscenely\Long\Hard\To\Type;
  
  class MyClass {
  }
  
  echo MyClass::class;
  // Output: Something\Obscenely\Long\Hard\To\Type\MyClass
  ?&gt;
  </code></pre>
  
  <p>Here is links for documentation and RFC
  <a href="http://php.net/oop5.basic#language.oop5.basic.class.class" rel="noreferrer">http://php.net/oop5.basic#language.oop5.basic.class.class</a>
  <a href="https://wiki.php.net/rfc/class_name_scalars" rel="noreferrer">https://wiki.php.net/rfc/class_name_scalars</a></p>
  
  <p>The question is:</p>
  
  <p>If I use Zend Framework 2, for example, which known as framework with huge php arrays configs, if I use for every class name in this configs resolution method with <code>::class</code> against just full names typed like strings <code>''</code>- is there a valuable performance impact?</p>
  
  <p>For example:</p>
  
  <pre><code>'controllers' =&gt; [
          'invokables' =&gt; [
              '\Controller\Monitor'  =&gt; 'Import\Controller\MonitorController',
  ...
  </code></pre>
  
  <p>vs</p>
  
  <pre><code>'controllers' =&gt; [
              'invokables' =&gt; [
                  '\Controller\Monitor'  =&gt; MonitorController::class,
      ...
  </code></pre>
  
  <p><strong>UPD:</strong></p>
  
  <p>My own tests</p>
  
  <p>I write simple fast test to benchmark</p>
  
  <pre><code>class MyClass
  {
  }
  
  class MyClass1
  {
  }
  
  class MyClass2
  {
  }
  
  class MyClass3
  {
  }
  
  /**
   * run many iteration loop for test percentage
   */
  function testString()
  {
      $results = [];
  
      for ($i = 0; $i &lt; 150000; $i++) {
  
          $results[] = [
              'controllers' =&gt; [
                  'invokables' =&gt; [
                      '\Controller\Monitor'  =&gt; 'Import\Controller\MonitorController',
                      '\Controller\Monitor2' =&gt; 'Import\Controller\MonitorController2',
                      '\Controller\Monitor3' =&gt; 'Import\Controller\MonitorController3',
                      '\Controller\Monitor4' =&gt; 'Import\Controller\MonitorController4',
                  ]
              ]
          ];
      }
  
      return $results;
  }
  
  function testClass()
  {
      $results = [];
  
      for ($i = 0; $i &lt; 150000; $i++) {
  
          $results[] = [
              'controllers' =&gt; [
                  'invokables' =&gt; [
                      '\Controller\Monitor'  =&gt; MyClass::class,
                      '\Controller\Monitor2' =&gt; MyClass1::class,
                      '\Controller\Monitor3' =&gt; MyClass2::class,
                      '\Controller\Monitor4' =&gt; MyClass3::class,
                  ]
              ]
          ];
      }
  
      return $results;
  }
  
  $token = Benchmark::start('testString');
  
  testString();
  
  Benchmark::end($token);
  
  $token = Benchmark::start('testClass');
  
  testClass();
  
  Benchmark::end($token);
  
  exit();
  </code></pre>
  
  <p>And results is similar to</p>
  
  <pre><code>testString
  215335.203125 Kbytes
  Time: 0.2604 Seconds
  testClass
  215337.1640625 Kbytes
  Time: 0.2508 Seconds
  </code></pre>
  
  <p>We can see that <code>::class</code> is faster. Run with latest php5.6.</p>
  
  <p>Can it be true ? </p>
  
  <p>P.S. It's not a duplicate of How to measure PHP code because:</p>
  
  <ol>
  <li>There is no information what I'm asking about in search engines. </li>
  <li><p>I don't know how to measure performance in this question context,
  because for this case running benchmark not enough and difficult. </p></li>
  <li><p>It's not simple to change thousands lines of code in real project
  config files. </p></li>
  <li>I want more detailed answer - not only numbers, but
  also why?</li>
  </ol>