[wp-trac] [WordPress Trac] #48082: Replace `dirname(__FILE__)` with `__DIR__` (Performance improvement, massive patch)

WordPress Trac noreply at wordpress.org
Thu Sep 19 21:00:14 UTC 2019


#48082: Replace `dirname(__FILE__)` with `__DIR__` (Performance improvement,
massive patch)
-------------------------------------------+-----------------------------
 Reporter:  ayeshrajans                    |      Owner:  (none)
     Type:  enhancement                    |     Status:  new
 Priority:  normal                         |  Milestone:  Awaiting Review
Component:  General                        |    Version:
 Severity:  minor                          |   Keywords:  has-patch
  Focuses:  performance, coding-standards  |
-------------------------------------------+-----------------------------
 PHP 5.3 added the `__DIR__` magic constant, that is same as
 `dirname(__FILE__)`. Because `dirname()` is a function call, this can have
 a performance overhead of the function call every time we use
 `dirname(__FILE__)` instead of `__DIR__`.

 Now that we require PHP 5.6 as the minimum version, we can drop the
 `dirname()` calls in favor of `__DIR__`.

 Attached is a massive patch that replaces all such calls with the magic
 constant. I have grepped the source for any further occurrences and we are
 clean now.

 I understand reviewing such a big patch is difficult, but hopefully we can
 contain this set of changes within one ticket, so they are easy to
 merge/deal with.

 Thank you.

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


More information about the wp-trac mailing list