[php-src] Issue #11258: [Feature request] Add a path_join function
| From: | shyim | Date: | Wed, 17 May 2023 13:34:00 +0000 |
| Subject: | [php-src] Issue #11258: [Feature request] Add a path_join function | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244471@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11258
Author: shyim
### Description
I really miss in PHP a function to join easily paths like the node's
[path.join](https://nodejs.org/api/path.html#pathjoinpaths) or in other languages.
I know it's really easy to implement in the user-land, but It would be nice to have this PHP as
this is some base filesystem functionality like
realpath, basename which
should be included by default (in my opinion).
## Usage would be like:
```php
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:
- does the before path end with a /, you have to normalize all parts
- for windows compatibility you have to use DIRECTORY_SEPERATOR