[PHP-DEV] Split as an alias to explode

Hello, internal folks.

We have `join` as an alias for `implode` so I think it makes sense to
have `split` as an alias to `explode`, doesn't it?

If I understood it correctly (I don't have any knowledge in PHP's
internal code) this doesn't add a lot of maintenance complexity so I
see no reason to not have it.

I tried starting a PR but it's probably missing stuff (although it
seems to work after I compiled and gave it a try).

Since this is such a small change, I wouldn't expect it to require an
RFC, but if it does, I'd be happy to write it.

Thanks in advance for any feedback.

On 15 August 2025 16:53:52 BST, Vinicius Dias <carlosv775@gmail.com> wrote:

Hello, internal folks.

We have `join` as an alias for `implode` so I think it makes sense to
have `split` as an alias to `explode`, doesn't it?

There's some history here that won't be obvious to anyone who has been using PHP for less than a decade.

In PHP 4 and 5 (and maybe even earlier) PHP had separate functions called explode() and split(). One split the string by an exact delimiter, the other split it by a regular expression pattern. For many use cases, these were interchangeable, because a pattern with no special characters in was matched literally; but in other cases, it caused a lot of confusion when split() gave unexpected results.

The entire "Posix-Compatible Regular Expressions" extension (ext/ereg) was deprecated in PHP 5.3, and removed in 7.0. That included the split() function, leaving us with only explode().

At that point, making split() an alias of explode() would have been possible, but unhelpful: rather than failing with "no such function", existing code would have subtly changed behaviour.

However, we have now had eight full releases with no built-in function called split(), so the chance of somebody upgrading in one go from PHP 5.6 to PHP 8.5 and missing the change seems very low. If we wanted to be really conservative, we could plan the alias for 9.0 so there were two clear major versions between removal and reuse of the name.

I believe straightforward aliases like this are a single line in a stub file, unless there's any compiler optimisations directly referencing the name.

As such, I would broadly support adding the alias: split() is the obvious name for this function, and as you say it would mirror join()

Cheers,

Rowan Tommins
[IMSoP]

If we wanted to be really conservative, we could plan the alias for 9.0 so there were two clear major versions between removal and reuse of the name.

I am not opposed to that, if people think it's safer. Do you think
that would require an RFC or just leaving the PR approved and open
until when there's a 9.0 branch?

Thank you for the historical context and for your feedback approving
the idea. :smiley:

Le 15 août 2025 à 17:53, Vinicius Dias <carlosv775@gmail.com> a écrit :

Hello, internal folks.

We have `join` as an alias for `implode` so I think it makes sense to
have `split` as an alias to `explode`, doesn't it?

If I understood it correctly (I don't have any knowledge in PHP's
internal code) this doesn't add a lot of maintenance complexity so I
see no reason to not have it.

I tried starting a PR but it's probably missing stuff (although it
seems to work after I compiled and gave it a try).

Adding split as an alias for explode by CViniciusSDias · Pull Request #19490 · php/php-src · GitHub

Since this is such a small change, I wouldn't expect it to require an
RFC, but if it does, I'd be happy to write it.

Thanks in advance for any feedback.

Hi,

We already have a function named `str_split()` which does something else. Adding a function named `split()` could cause confusion.

—Claude

Hi

On 8/15/25 17:53, Vinicius Dias wrote:

We have `join` as an alias for `implode` so I think it makes sense to
have `split` as an alias to `explode`, doesn't it?

I'd rather have fewer aliases rather than more of them. Using `join()` instead of `implode()` is already somewhat obscure (and likewise is `sizeof()` instead of `count()`, which I don't think I've ever seen). I don't see value in having multiple names for the same thing, that will just cause confusion for folks that are used to the other name.

Since this is such a small change, I wouldn't expect it to require an
RFC, but if it does, I'd be happy to write it.

As implied above and also indicated by the changed labels on the PR: RFC please.

Best regards
Tim Düsterhus

We already have a function named `str_split()` which does something else. Adding a function named `split()` could cause confusion.

I totally understand your point, but I also think that it's way more
common for people to assume `str_split` does what `explode` does and
get surprised when they see it's not the case.
I had this happening during a few conversations in PHP User Groups meetups.

I agree that having `split` and `str_split` with such different
behaviors isn't great, but I also think the benefit for newcomers to
the language to see `split` just like we have in several other
languages outweighs the possible confusion.

---

I don't see value in having multiple names for the same thing, that will just cause confusion for folks that are used to the other name.

This is also a very valid point and I understand this line of thought.
My thought, though, is: people coming from different languages are
used to seeing `split(str)` or `str.split()`, so this would make PHP a
bit more familiar for them. Small changes like that can make a
language more "liked" for people learning them, IMO.

As implied above and also indicated by the changed labels on the PR: RFC please.

No problem. I'll send a new e-mail to the list asking for karma (or
can this message in this thread serve as the request already)?

Thank you.

Hi

On 8/15/25 23:18, Vinicius Dias wrote:

I don't see value in having multiple names for the same thing, that will just cause confusion for folks that are used to the other name.

This is also a very valid point and I understand this line of thought.
My thought, though, is: people coming from different languages are
used to seeing `split(str)` or `str.split()`, so this would make PHP a
bit more familiar for them. Small changes like that can make a
language more "liked" for people learning them, IMO.

These folks coming from other languages would naturally need to learn about `explode()`, since that's *everywhere* and folks that are already familiar with PHP are unlikely to go ahead and bulk replace everything. I also don't believe that a having a more familiar name for a single function in the stdlib is actually going to make a meaningful difference.

If *really* desired, `use function explode as split;` already works.

As implied above and also indicated by the changed labels on the PR: RFC please.

No problem. I'll send a new e-mail to the list asking for karma (or
can this message in this thread serve as the request already)?

This thread should be sufficient. We would need your Wiki username, though.

Best regards
Tim Düsterhus

I don’t see any benefit to re-adding split() to the language. Why create more keywords for the sake of a function name with fewer characters? Code golfing isn’t a goal of the language.

Rather, we should be going the other way and removing aliases that are not needed such as chop(), sizeof(), join(), etc.

Adding new function names should be done with a particular benefit in mind.

For example, create the preg_escape() function and allow its first parameter to be scalar or a flat array (like multiple other preg_ functions) so that you don’t have to call preg_quote() while looping an array of terms before imploding with pipes to create a dynamic pattern. Then the semantically misleading preg_quote() function (which doesn’t actually add quotes) can be removed and the language is left with a more usable, more indictively named function.

My 2 cents,
mickmackusa

On Fri, Aug 15, 2025, 10:30 PM mickmackusa <mickmackusa@gmail.com> wrote:

I don’t see any benefit to re-adding split() to the language. Why create more keywords for the sake of a function name with fewer characters? Code golfing isn’t a goal of the language.

Rather, we should be going the other way and removing aliases that are not needed such as chop(), sizeof(), join(), etc.

Adding new function names should be done with a particular benefit in mind.

For example, create the preg_escape() function and allow its first parameter to be scalar or a flat array (like multiple other preg_ functions) so that you don’t have to call preg_quote() while looping an array of terms before imploding with pipes to create a dynamic pattern. Then the semantically misleading preg_quote() function (which doesn’t actually add quotes) can be removed and the language is left with a more usable, more indictively named function.

My 2 cents,
mickmackusa

Ancient history aside and forward looking; JavaScript took a huge boom in recent years and overtook PHP in areas of new adoption and code DX

Making it a smoother transition for JS devs to hop back on the modern PHP train is in all our shared interest in terms of user base, and split() would help this.

So why not?

Making it a smoother transition for JS devs to hop back on the modern PHP train is in all our shared interest in terms of user base, and split() would help this.

So why not?

That is exactly my line of thought.

This thread should be sufficient. We would need your Wiki username, though.

My username is cviniciussdias

Thank you

On 15. Aug 2025, at 22:53, Vinicius Dias <carlosv775@gmail.com> wrote:

Hello, internal folks.

We have `join` as an alias for `implode` so I think it makes sense to
have `split` as an alias to `explode`, doesn't it?

If I understood it correctly (I don't have any knowledge in PHP's
internal code) this doesn't add a lot of maintenance complexity so I
see no reason to not have it.

I tried starting a PR but it's probably missing stuff (although it
seems to work after I compiled and gave it a try).

Adding split as an alias for explode by CViniciusSDias · Pull Request #19490 · php/php-src · GitHub

Since this is such a small change, I wouldn't expect it to require an
RFC, but if it does, I'd be happy to write it.

Thanks in advance for any feedback.

For consistency with other newish string functions, I would like it better to have a `str_` prefix. However, `str_split` is already taken.

On 15.08.2025 at 23:47, Paul Dragoonis wrote:

On Fri, Aug 15, 2025, 10:30 PM mickmackusa <mickmackusa@gmail.com> wrote:

I don't see any benefit to re-adding split() to the language. Why create
more keywords for the sake of a function name with fewer characters? Code
golfing isn't a goal of the language.

Ancient history aside and forward looking; JavaScript took a huge boom in
recent years and overtook PHP in areas of new adoption and code DX

Making it a smoother transition for JS devs to hop back on the modern PHP
train is in all our shared interest in terms of user base, and split()
would help this.

So why not?

Because it would still be rather confusing to JavaScript developers who
are used to

  str.split(separator)

and now would have to deal with

  split(separator, str)

In my opinion, the difficulty is not the name the name of the function,
but rather that it is a function and not a method. Having a different
function name, can even be slightly beneficial to stress that difference.

Christoph

On 16 August 2025 10:16:40 BST, "Christoph M. Becker" <cmbecker69@gmx.de> wrote:

Because it would still be rather confusing to JavaScript developers who
are used to

str.split(separator)

and now would have to deal with

split(separator, str)

The fact that PHP doesn't have methods on strings, numbers, and lists, is something you learn once and applies to dozens of different functions. It's like saying "it would be rather confusing that you have to write split($foo, $bar) instead of split(foo, bar)".

And why focus on JavaScript anyway? Have a look at this comparison of how to "tokenize" a string in dozens of different languages: <https://rosettacode.org/wiki/Tokenize_a_string&gt;

If they have a built-in implementation, it is nearly always called "split", regardless of whether it's a method, a free function, an operator, or whatever else. Apart from PHP, the only built-ins called "explode" appear in Modula-3, and an obscure teaching language called Basic256.

Let's face it, "exploding a string" is a slightly odd metaphor. I wouldn't be surprised if it causes extra confusion in people who don't speak English as a first language, as well.

I can only assume the original split() function came first, taking a regex because of the influence of Perl; and explode() was chosen when hunting around for a distinct name later.

I do accept the argument that aliases can lead to confusion when reading code that mixes them, though. I've seen people completely convinced that sizeof() means something different from count()

Rowan Tommins
[IMSoP]

Le 16 août 2025 à 11:16, Christoph M. Becker cmbecker69@gmx.de a écrit :

On 15.08.2025 at 23:47, Paul Dragoonis wrote:

On Fri, Aug 15, 2025, 10:30 PM mickmackusa mickmackusa@gmail.com wrote:

I don’t see any benefit to re-adding split() to the language. Why create
more keywords for the sake of a function name with fewer characters? Code
golfing isn’t a goal of the language.

Ancient history aside and forward looking; JavaScript took a huge boom in
recent years and overtook PHP in areas of new adoption and code DX

Making it a smoother transition for JS devs to hop back on the modern PHP
train is in all our shared interest in terms of user base, and split()
would help this.

So why not?

Because it would still be rather confusing to JavaScript developers who
are used to

str.split(separator)

and now would have to deal with

split(separator, str)

In my opinion, the difficulty is not the name the name of the function,
but rather that it is a function and not a method. Having a different
function name, can even be slightly beneficial to stress that difference.

Christoph

Apart from the order of arguments, there is another confusing difference between the PHP function and the JavaScript one. Both accept an additional parameter named limit, with subtly but fundamentally different semantics, and you have to read very carefully the documentation (or test the function) to understand it. (And to be clear, I am not speaking of the fact that PHP accept a “negative” limit: that one is not subtle enough.)

The difference of naming is probably the least problematic difference, and attempting to reduce that specific difference without regard to the other ones, won’t reduce confusion.

—Claude

On 17/08/2025 18:15, Claude Pache wrote:

The difference of naming is probably the least problematic difference, and attempting to reduce that specific difference without regard to the other ones, won’t reduce confusion.

As I said in my previous e-mail, I think this is a straw man argument.

A developer coming to PHP from any combination of JavaScript, Perl, C#, Java, VisualBasic, Python, Ruby, Swift, Elixir, Dart, Rust, even Excel ... is going to look first for a function called "split" or some variation of that. If they have any common sense, they'll know they need to look up exactly what arguments it needs, and what options it provides.

Unless for some reason they're familiar with the 1980s research language Modula-3, or some equally obscure language not listed on the Rosetta Code page I linked, they are never going to look for a function called "explode".

If we don't want to add an alias, we should probably add a fake manual entry pointing people in the right direction, like we have for "delete": https://www.php.net/delete

--
Rowan Tommins
[IMSoP]

On Mon, Aug 18, 2025, at 8:36 AM, Rowan Tommins [IMSoP] wrote:

On 17/08/2025 18:15, Claude Pache wrote:

The difference of naming is probably the least problematic difference,
and attempting to reduce that specific difference without regard to
the other ones, won’t reduce confusion.

As I said in my previous e-mail, I think this is a straw man argument.

A developer coming to PHP from any combination of JavaScript, Perl, C#,
Java, VisualBasic, Python, Ruby, Swift, Elixir, Dart, Rust, even Excel
... is going to look first for a function called "split" or some
variation of that. If they have any common sense, they'll know they need
to look up exactly what arguments it needs, and what options it provides.

Unless for some reason they're familiar with the 1980s research language
Modula-3, or some equally obscure language not listed on the Rosetta
Code page I linked, they are never going to look for a function called
"explode".

If we don't want to add an alias, we should probably add a fake manual
entry pointing people in the right direction, like we have for "delete":
https://www.php.net/delete

--
Rowan Tommins
[IMSoP]

I'd prefer the doc page, frankly. I agree our explode() is different enough from what other languages have that there's little point in adding an alias, which would likely cause even more confusion.

If we ever manage to get methods on strings by some mechanism or another, we can consider naming that split() and having its behavior match that in our sibling languages. But for now, I'd prefer to not mess with it.

--Larry Garfield

Am 18.08.2025 um 15:36 schrieb Rowan Tommins [IMSoP] <imsop.php@rwec.co.uk>:

A developer coming to PHP from any combination of JavaScript, Perl, C#, Java, VisualBasic, Python, Ruby, Swift, Elixir, Dart, Rust, even Excel ... is going to look first for a function called "split" or some variation of that. If they have any common sense, they'll know they need to look up exactly what arguments it needs, and what options it provides.

I don't think people nowadays search through documentation for a specific function name.
I am pretty confident that people will either Google/DDG/... or ask an AI chat something like "How do I split a string in PHP?" which gives a complete code example including parameter order.

If we don't want to add an alias, we should probably add a fake manual entry pointing people in the right direction, like we have for "delete": https://www.php.net/delete

This would IMHO be better suited for a tutorial / learning website, I am not convinced that we need to extend the reference documentation (or even the language) with entries of synonyms/aliases people might be looking for.

So, in short, that's a -1 for a split alias from me.

Regards,
- Chris

On Mon, 18 Aug 2025 at 17:18, Christian Schneider <cschneid@cschneid.com> wrote:

Am 18.08.2025 um 15:36 schrieb Rowan Tommins [IMSoP] <imsop.php@rwec.co.uk>:

A developer coming to PHP from any combination of JavaScript, Perl, C#, Java, VisualBasic, Python, Ruby, Swift, Elixir, Dart, Rust, even Excel … is going to look first for a function called “split” or some variation of that. If they have any common sense, they’ll know they need to look up exactly what arguments it needs, and what options it provides.

I don’t think people nowadays search through documentation for a specific function name.
I am pretty confident that people will either Google/DDG/… or ask an AI chat something like “How do I split a string in PHP?” which gives a complete code example including parameter order.

If we don’t want to add an alias, we should probably add a fake manual entry pointing people in the right direction, like we have for “delete”: https://www.php.net/delete

This would IMHO be better suited for a tutorial / learning website, I am not convinced that we need to extend the reference documentation (or even the language) with entries of synonyms/aliases people might be looking for.

So, in short, that’s a -1 for a split alias from me.

Regards,

  • Chris

Personally, after 15+ years with PHP, I never know which one I need: implode or explode, neither name makes intuitive sense to me and I do an in-ide doc lookup to see if I got the right one every time.

Making a programming language intuitive and self-explanatory in ENGLISH (i.e. not in javascript, not in php), makes it more efficient - and more loved.

I think this alias is definitely a worthwhile addition.