Re: Adding a more logical string slicing function to PHP

From: Date: Thu, 31 Mar 2011 14:49:50 +0000
Subject: Re: Adding a more logical string slicing function to PHP
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-51765@lists.php.net to get a copy of this message
On 31.03.11 16:41, Philip Olson wrote: > On Mar 30, 2011, at 1:42 PM, Martin Jansen wrote: >> Both str_startswith and str_endswith have been suggested in the past: >> >> http://marc.info/?t=121647230100001&r=1&w=2 >> >> I recently got around to merge them into a largely unfinished extension >> so they are archived somewhere safe: >> https://github.com/mj/php-ext-str > > I see str_contains() on the TODO there. I've always wanted in_string() so am glad to see a > similar item. Using strpos() for this task feels dirty, much like using arrpos() for arrays would ;) >From time to time I have wondered if it made sense to add a new operator "in" that works on variables of different type and could replace in_string/str_contains: if ("a" in "abc") { ... } if ("a" in array("a", "b", "c")) { ... } if ("a" in $obj) { /* true if $obj->__contains("a") returned true */ } I suspect there is a massive potential for WTF issues in there and that most people would hate this feature. Which is why I am only thinking out loud here -- I have zero intentions to suggest this as a future enhancement for PHP. ;-) - Martin

« previous php.internals (#51765) next »