Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define split as an alias for explode #17268

Closed
nbro opened this issue Dec 25, 2024 · 5 comments
Closed

Define split as an alias for explode #17268

nbro opened this issue Dec 25, 2024 · 5 comments

Comments

@nbro
Copy link

nbro commented Dec 25, 2024

Description

One thing that I find hard to memorise is which one actually splits a string and which one actually joins an array, between implode and explode.

So, when I need to join, I always use the alias join, but I still need to look up in the documentation which one actually splits.

I've been programming mostly in Python, so that's why I highly prefer join and I'd also prefer that split was introduced as an alias for explode (again I had to check that this was the actual function).

Would there be any future function that we might want to call split and that does something different than explode? In any case, it will most likely not be as useful as explode, so we can probably sacrifice the future in this case.

@devnexen
Copy link
Member

Hi @nbro I would suggest to discuss it in the internal mailing list.

@nbro
Copy link
Author

nbro commented Dec 26, 2024

I wonder why people gave the thumbs down.

We already have the join alias for implode, and, for some reason, we don't have the split alias for explode, even though the documentation for this function explicitly states

explode — Split a string by a string

Unless there's a good reason not to introduce this alias, then it should be introduced.

Now, I'm curious to know why the join was then introduced as an alias for implode. Someone must have thought that join was more intuitive that implode.

Curiously, the documentation for implode states

implode — Join array elements with a string

@MorganLOCode
Copy link

split, explode, join, and implode were all introduced in PHP 3.0; the first one split on a regular expression and the second on a fixed string. The other two functions were created as complements to the first two, but there was no meaningful way to "join" on a regular expression so the two functions ended up identical.

And as @devnexen has already suggested, further discussion would be better moved to the mailing list.

@nbro
Copy link
Author

nbro commented Dec 27, 2024

@MorganLOCode Where is the function called split in the documentation? I couldn't find it. Yes, there are different "split" functions and one for the regular expressions, but this issue is not about it.

@devnexen devnexen closed this as not planned Won't fix, can't repro, duplicate, stale Dec 27, 2024
@MorganLOCode
Copy link

Where is the function called split in the documentation?

https://web.archive.org/web/20180516162407/http://www.php.net/split

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants