Skip to content

Commit

Permalink
Code Modernization: Replace substr( PHP_OS, 0, 3 ) calls with `PHP_…
Browse files Browse the repository at this point in the history
…OS_FAMILY`.

The `PHP_OS_FAMILY` constant indicates the operating system family PHP was built for, and is available as of PHP 7.2.0.

Reference: [https://www.php.net/manual/en/reserved.constants.php#constant.php-os-family PHP Manual: Predefined Constants: PHP_OS_FAMILY].

Follow-up to [23255], [57753], [57985], [58678].

Props ayeshrajans, jrf.
See #61574.

git-svn-id: https://develop.svn.wordpress.org/trunk@58684 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Jul 7, 2024
1 parent 55e0faf commit e3e7fdb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2257,11 +2257,11 @@ function get_temp_dir() {
* @return bool Whether the path is writable.
*/
function wp_is_writable( $path ) {
if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ) {
if ( 'Windows' === PHP_OS_FAMILY ) {
return win_is_writable( $path );
} else {
return @is_writable( $path );
}

return @is_writable( $path );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/filesystem/wpFilesystemDirect/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function create_file_if_needed( $path, $contents = '' ) {
* @return bool Whether the operating system is Windows.
*/
public static function is_windows() {
return 'WIN' === substr( PHP_OS, 0, 3 );
return 'Windows' === PHP_OS_FAMILY;
}

/**
Expand Down

0 comments on commit e3e7fdb

Please sign in to comment.