Adding a more logical string slicing function to PHP
| From: | Dan Birken | Date: | Wed, 30 Mar 2011 06:06:37 +0000 |
| Subject: | Adding a more logical string slicing function to PHP | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-51745@lists.php.net to get a copy of this message | ||
My apologizes if I am bringing up a topic that has been discussed before,
this is my first time wading into the PHP developers lists and I couldn't
find anything particularly relevant with the search.
Here is a bug I submitted over the weekend (
http://bugs.php.net/bug.php?id=54387) with an
attached patch that adds a
str_slice() function into PHP. This function is just a very simple string
slicing function, with the logical interface of str_slice(string, start,
[end]). It is of course meant to replace substr() as an interface for
string slicing.
I detailed the reasons I submitted the patch in the bug a little bit, but
the main reason is that I think the substr() function is really overly
confusing and just not an intuitive method of string slicing, which is
exceedingly common functionality. I realize we don't want to go around
adding lots of random little functions into the language that don't offer
much, but the problem with that is that if we have a function like substr()
with an unusual and unintuitive interface, it becomes unchangeable due to
legacy issues and then you can never improve. I think this particular
functionality is important enough to offer an updated interface. In the bug
I also pointed to two related bugs that would be essentially fixed with this
patch.
-Dan