I think that depending on the platform, you might get an invalid regular expression for the first argument.
Your solution is elegant in design. Good coding. But remember that directory separators are usually special characters. Some acceleration may be required.
EDIT # 1 I liked the proposed solution
$sepPresent = $path{strlen($path) - 1} == DIRECTORY_SEPARATOR ? true : false;
And for its development, I suggest:
$sepPresent = $path{strlen($path) - strlen(DIRECTORY_SEPARATOR)} === DIRECTORY_SEPARATOR ? true : false;
source share