Skip to content

path_is_absolute: narrow return type and assert param type - #482

Merged
szepeviktor merged 2 commits into
php-stubs:masterfrom
IanDelMar:path_is_absolute
Aug 24, 2026
Merged

path_is_absolute: narrow return type and assert param type#482
szepeviktor merged 2 commits into
php-stubs:masterfrom
IanDelMar:path_is_absolute

Conversation

@IanDelMar

Copy link
Copy Markdown
Contributor

path_is_absolute():

function path_is_absolute( $path ) {
	if ( wp_is_stream( $path ) && ( is_dir( $path ) || is_file( $path ) ) ) {
		return true;
	}
	if ( realpath( $path ) === $path ) {
		return true;
	}
	if ( strlen( $path ) === 0 || '.' === $path[0] ) {
		return false;
	}
	if ( preg_match( '#^[a-zA-Z]:\\\\#', $path ) ) {
		return true;
	}
	return ( '/' === $path[0] || '\\' === $path[0] );
}

Each if branch as well as the final else branch (return) is false for both, '' and '0'. Therefore, path_is_absolute() always returns false for '' and '0'.

Related: #481

@szepeviktor
szepeviktor merged commit 349dc82 into php-stubs:master Aug 24, 2026
8 checks passed
@IanDelMar
IanDelMar deleted the path_is_absolute branch August 25, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants