[wp-trac] [WordPress Trac] #36963: a little performance improvment: replace dirname(__FILE__) with __DIR__

WordPress Trac noreply at wordpress.org
Sat May 28 08:19:25 UTC 2016


#36963: a little performance improvment: replace dirname(__FILE__) with __DIR__
--------------------------+-----------------------------
 Reporter:  nigro.simone  |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  4.5.2
 Severity:  normal        |   Keywords:
  Focuses:  performance   |
--------------------------+-----------------------------
 A little performance improvment is replace

 {{{#!php
 dirname(__FILE__)
 }}}

 with

 {{{
 __DIR__

 }}}

 Their result is exactly the same ; so, no difference on that.

 For example, the two following lines :

 {{{#!php
 <?php
 var_dump(dirname(__FILE__));
 var_dump(__DIR__);
 }}}

 Will both give the same output :


 {{{
 string '/htdocs/wordpress' (length=17)
 }}}

 But, there are at least two differences :

 1) _DIR_ only exists with PHP >= 5.3
 2) _DIR_ is evaluated at compile-time, while dirname(_FILE_) means a
 function-call and is evaluated at execution-time, so, _DIR_ is faster.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36963>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list