On Wed, May 17, 2023 at 11:13 AM Timo Tijhof <ttij...@wikimedia.org> wrote:
> In case it is of interest, the implementation we use on Wikipedia > as part of MediaWiki, is available on Packagist: > > https://packagist.org/packages/wikimedia/relpath > https://www.mediawiki.org/wiki/RelPath > > -- > Timo Tijhof, > Wikimedia Foundation. > https://timotijhof.net/ > > > > On Wed, May 17, 2023 at 3:54 PM <p...@shyim.de> wrote: > > > Hey, > > > > I have created on GitHub a feature request for a path_join function ( > > https://github.com/php/php-src/issues/11258) and got the label that this > > requires a RFC. So I am here now :) > > > > The idea is to provide in PHP itself a function to join filesystem paths > > (idea: path_join) like in other languages, node as example ( > > https://nodejs.org/api/path.html#pathjoinpaths). For me this function is > > some kind of base filesystem functionality like basename, realpath. > > > > Example usage: > > > > path_join('/base', 'my', 'path'); // /base/my/path > > path_join('/base', 'my', 'path', 'test', '..'); // /base/my/path > > > > Why not just string concatenation? > > > > When you concat just the paths you have to think about: > > - normalize string part to strip ending slash > > - for windows compatibility you have to use DIRECTORY_SEPERATOR > > > > I think this can improve the developer experience when working with > > filesystems a lot and people can delete their implementation. > > > > I am really looking for your feedback, right now I have no “karma points” > > to create a RFC in the wiki :) > > > > Thanks, > > Soner > Definitely a useful feature, but not sure it needs to be a core function. It's very easy to implement in userland. Userland implementation also allows people to better customize it to their needs. Never going to be using it on windows? Just use /. Only going to be using it on windows? Just use \. Need to support URLs as well as windows directories, create a method that allows specifying the separator. Just for the simple case of windows vs *nix directories, how is it determined which separator to use? If it's the operating system that the code is running on, then what about if I need to generate a *nix style path even though I'm running on Windows, or vice versa? My feeling is that for the function to be easy to use, you have to cut out too many scenarios which causes users to have to fallback to their own implementations anyway. Finally, there aren't going to be any meaningful performance gains which would possibly justify not implementing it in userland. -- Chase Peeler chasepee...@gmail.com