Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#48075 closed task (blessed) (fixed)

Remove conditional use of PHP realpath()

Reported by: jrf's profile jrf Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.3 Priority: normal
Severity: normal Version: 5.3
Component: General Keywords: has-patch
Focuses: performance, coding-standards Cc:


While working on #48074 / looking for code which can be removed now support for PHP < 5.6.20 has been dropped, I came across two instances of conditional use of the realpath() function.

        if ( function_exists( 'realpath' ) ) {
                $path = realpath( $path );

Now, there are only two reasons I can think for this code to exist:

  1. Support for PHP < 4.

The `realpath()` function was introduced in PHP 4.0.0. It might be that this code is so ancient that it is from before that time.
I've tried to trace this back, but got stuck somewhere in 2009.

  1. Hosts disabling the function using the `disabled_functions` ini directive.

I honestly don't know if that's a thing and it would be pretty foolish (of hosts) if they did, but that's the only other reason I could think of for this code to exist.

It would be great if someone with a long memory could chime in here.

If the reason is 1), the removal of these conditions is long overdue.

If the reason is 2), based on a quick scan, there are 27 more instances within WP where realpath() is used without a function_exists() check.

I'm presuming, for now, that the reason is 1) and am attaching a patch to remove the condition.

If by some happenstance, the reason for this code would turn out to be 2), a new patch would need to be created to add the condition to the other 27 instance of realpath() in core (or better yet a wp_realpath() function or similar should be added instead).

Attachments (2)

48075-src-Remove-work-arounds-for-realpath.patch (1.4 KB) - added by jrf 4 years ago.
48075.1.patch (457 bytes) - added by dkarfa 4 years ago.

Download all attachments as: .zip

Change History (7)

4 years ago

#1 @dkarfa
4 years ago

Kindly ignore my last patch.

Last edited 4 years ago by dkarfa (previous) (diff)

#2 @netweb
4 years ago

  • Milestone changed from Awaiting Review to Future Release

#3 @SergeyBiryukov
4 years ago

  • Milestone changed from Future Release to 5.3

#4 @SergeyBiryukov
4 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 46210:

Code Modernization: Remove conditional use of PHP realpath().

The realpath() function was introduced in PHP 4.0.0. There's no point in checking if the function exists in PHP 5.6+, in only 2 instances out of 29.

Props jrf.
Fixes #48075.

#5 @jrf
4 years ago

Thanks @SergeyBiryukov !

Note: See TracTickets for help on using tickets.