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

WordPress Trac noreply at wordpress.org
Fri May 6 20:54:26 UTC 2022

#48082: Replace `dirname(__FILE__)` with `__DIR__` (Performance improvement,
massive patch)
 Reporter:  ayeshrajans       |       Owner:  SergeyBiryukov
     Type:  enhancement       |      Status:  closed
 Priority:  normal            |   Milestone:  5.4
Component:  General           |     Version:
 Severity:  minor             |  Resolution:  fixed
 Keywords:  has-patch needs-  |     Focuses:  performance, coding-standards
  testing                     |

Comment (by azaozz):

 Replying to [comment:20 SergeyBiryukov]:

 Thanks for the explanation! Was really helpful :)

 > Just noting that `include( 'file.php' );` triggers two WPCS warnings:
 > {{{
 > | WARNING | [x] "include" is a statement not a function; no parentheses
 are required
 > |         |     (PEAR.Files.IncludingFile.BracketsNotRequired)
 > | WARNING | [x] File is being unconditionally included; use "require"
 > |         |     (PEAR.Files.IncludingFile.UseRequire)
 > }}}

 Yes, seems that perhaps WPCS got it wrong here :)

 The "brackets are not required" does not mean they are "forbidden", right?
 If not forbidden, does it make sense to use them in cases where that may
 improve readability a bit? IMHO it is a tiny bit more readable to group
 together a path that is being concatenated from several strings at the
 same time.

 The `include` to `require` replacements seem fine. Just thinking that
 perhaps it would have been better to do them in another ticket and perhaps
 do some testing how much the slow-down would be if at all measurable.

 I'm not thinking of opening new tickets for the same things, or reverting
 removal of brackets, or anything. Just trying to figure out where these
 changes come from and how they were decided. Seems that core readability
 keeps being reduced little by little, and most of the decisions concerning
 it are done without realizing they would affect readability.

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

More information about the wp-trac mailing list