Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#36963 closed enhancement (duplicate)

a little performance improvment: replace dirname(__FILE__) with __DIR__

Reported by: nigrosimone's profile nigro.simone Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.5.2
Component: General Keywords:
Focuses: performance Cc:

Description

A little performance improvment is replace

dirname(__FILE__)

with

__DIR__

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

For example, the two following lines :

<?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.

Change History (1)

#1 @ocean90
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
  • Type changed from defect (bug) to enhancement

Duplicate of #32274.

Note: See TracTickets for help on using tickets.