Skip to content

[Feature request] Add a path_join function #11258

@shyim

Description

@shyim

Description

I really miss in PHP a function to join easily paths like the node's path.join 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:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions