====== PHP RFC: Create "split" as an alias to "explode" ====== * Version: 1.2 * Date: 2025-08-17 * Author: Vinicius Dias, carlosv775@gmail.com * Status: Voting * Implementation: https://github.com/php/php-src/pull/19490 ===== Introduction ===== PHP has the concept of [[https://www.php.net/manual/en/aliases.php|alias functions]], where a function can have more than one name. Here are some examples of aliases: ^ Alias ^ Function ^ | ''sizeof'' | ''count'' | | ''chop'' | ''rtrim'' | | ''die'' | ''exit'' | | ''join'' | ''implode'' | In several languages, the inverse operation of ''join'' is ''split'', but in PHP, we call it ''explode'' (the inverse of ''implode''). This RFC proposes a new alias to the ''explode'' function called ''split''. ===== Proposal ===== Several languages use the word ''split'' for the function that separates a string into an array using a separator, and ''join'' for its inverse operation (joining an array into a string). PHP functions for those purposes are, respectively, ''explode'' and ''implode''. That difference from the majority of languages was mitigated with a ''join'' alias to the ''implode'' function, so a person coming to PHP from a different language has one less "strange" thing to get used to, but there is no ''split'' alias to ''explode''. In older versions of PHP, there was a function named ''split'' which was part of the extension ''ereg'' and could be used to split a string into an array by a regular expression pattern. The ''ext/ereg'' was deprecated in PHP 5.3 and removed in PHP 7.0. Since then, the ''split'' function name has not been used and is available. This RFC has one simple purpose: creating a new function alias called ''split'' that will execute the exact same code as ''explode''. Neither parameters nor any behavior will change with this RFC. It will only make the following possible: Which would result in the following output: Array ( [0] => one [1] => two [2] => three [3] => four ) Array ( [0] => one [1] => two|three|four ) ==== Why add a new alias? ==== Some people might question how useful a new alias would be, and that is a valid concern. Whenever we developers learn a new language, we find similarities and differences from the programming languages we already know. When something is similar, we tend to assimilate it faster and feel more comfortable with the feature in question. Whenever something is very different from what we are used to, it adds some cognitive load and can make the process more challenging. As it was mentioned previously (and added to the references), multiple other programming languages use ''split'' as the word for this functionality, so having it in PHP would just make people coming from those languages a little bit more comfortable. [[https://news-web.php.net/php.internals/128486|As Paul Dragoonis mentioned]]: > 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. This applies to other languages too. In the references, I am adding a small number of "complaints" in social media where users mention that ''split'' would be an interesting alias. ==== Caveats and Arguments against ==== === Dislike for aliases === Some people might be against the idea of adding aliases to PHP, even though we already have that concept and multiple aliases are available. If we don't want to keep using aliases, we should create a separate RFC to remove the existing ones and prevent new ones from being created. Since this is not the case, an alias is a valid part of the language and a new one is a valid approach. === Confusion with other functions === == str_split == PHP has a [[https://www.php.net/manual/en/function.str-split.php|''str_split'']] function that performs a different task. It converts a string into an array, but doesn't use a separator. It separates the string by a //chunk size//, which is passed as the second parameter. == ext/ereg split == As mentioned in the **Proposal** section, ''ext/ereg'' had a ''split'' function, but it was deprecated in PHP 5.3 and removed in PHP 7.0. A person migrating from PHP 5.3 to PHP 8.6 would be surprised by a new behavior of the ''split'' function, but that is a scenario highly unlikely to happen. == mb_split == The ''mb_split'' function has a similar behavior to the old ''ext/ereg'' ''split'', but it depends on Oniguruma, which is not maintained anymore since 2025-04-24 and there is an RFC to deprecate (and remove) it: [[eol-oniguruma|PHP RFC: Oniguruma maintenance was end]] ===== Backward Incompatible Changes ===== With this new alias, ''\split()'' would no longer be available to userland. ===== Proposed PHP Version(s) ===== 8.6 ===== RFC Impact ===== ==== To the Ecosystem ==== Searching for the usage of ''split'' on GitHub, most of the occurances are either for repositories from over 10+ years without any activity or with the function being used in a way that would not be a BC change (or both). Examples of cases where the behavior would not change: https://github.com/cloudfour/image-breakpoints/blob/master/bps.php#L97C1-L103C64 https://github.com/fruminator/openstreetblock/blob/master/osb.php#L26: https://github.com/bandoche/pyLine/blob/master/gd2.php#L178: ==== To Existing Extensions ==== None ==== To SAPIs ==== None ===== Voting Choices ===== * Yes * No * Abstain ===== Patches and Tests ===== https://github.com/php/php-src/pull/19490 ===== References ===== * Examples of languages that use ''split'' * [[https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/String/split|JavaScript]] * [[https://docs.python.org/3.3/library/stdtypes.html#str.split|Python]] * [[https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#split-java.lang.String-|Java]] * [[https://doc.rust-lang.org/std/primitive.str.html#method.split|Rust]] * [[https://ruby-doc.org/3.4.1/String.html#method-i-split|Ruby]] * [[https://pkg.go.dev/strings#Split|Golang]] * [[https://hexdocs.pm/elixir/1.12/String.html#split/3|Elixir]] * [[https://clojuredocs.org/clojure.string/split|Clojure]] * Social Media posts about the subject * https://x.com/ModestasMV/status/1770456102443880624 * https://x.com/misaalanshori03/status/1730592634161565954 * https://x.com/aeportugal/status/1494460629268189185 * https://x.com/RobinCalmegard/status/1484875255755821058 * https://x.com/mmartin_joo/status/1956360244222701598