Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94717 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19533 invoked from network); 26 Jul 2016 23:40:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jul 2016 23:40:00 -0000 Authentication-Results: pb1.pair.com header.from=me@daveyshafik.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=me@daveyshafik.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain daveyshafik.com from 209.85.220.172 cause and error) X-PHP-List-Original-Sender: me@daveyshafik.com X-Host-Fingerprint: 209.85.220.172 mail-qk0-f172.google.com Received: from [209.85.220.172] ([209.85.220.172:33466] helo=mail-qk0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8B/00-18985-CC4F7975 for ; Tue, 26 Jul 2016 19:39:58 -0400 Received: by mail-qk0-f172.google.com with SMTP id p74so20637703qka.0 for ; Tue, 26 Jul 2016 16:39:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daveyshafik-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=LQ/mtG0Bqgca5Vv7oKwecQ7GmW8DWfgD1roqabK3xpM=; b=tyJxvucQjERWAg+pR7B2ZulW8UT9QZQTNqHnbsHTcLcz/65odTWxhJCuuHjkqqVfbf BwBK4BkUYvOttsGkXAFywKoCGNc5CXg3oYiYlAXyN7qSN+voe1fqAbbsFgUsBDFmQTA7 g3r4GZYMsS+XS05lt5lZNopbChKRP5f4eu/gJrwIVS1b3F80s9mzda+8zrING4M7J8OH vCqOUA3D8DSF++BhrnaIO8tATbShzJYVXnztJn6M5x8xLGt/rPXSkdG474wl3QBP+6BO iK54bg4/VoLiTzT9DMMY91tnGHPJJfkTxR07EQb2fPFRgo00NanPflCVarBp/hu2CfKg yzjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=LQ/mtG0Bqgca5Vv7oKwecQ7GmW8DWfgD1roqabK3xpM=; b=aDw8qfCeaOG4NtR4xvqsFGJ1yjE94xn3TsDdep1pgPzPV64OiaObTX7YDOpKXsesqD sJeLkNtbRhco8nyS1MwIfwARzTUjiNxkELxHfhdFUYcT7HuBpxxg+hUMet5WBjKlMVH5 K155OOFl6rngBRhgtF+oXUDUVPt32+U3d3lTD1BMl5hJUxq9nwpb2CIrXWbFhW47bEfQ HPxBKOZRkyvaVnPPBx3QRDUlJTmq1QE/hez+GONUFp3gL1V9S0hyFV2W2hI1ArwrHWYB tPXhCFDbux4Ijf1OMTVIpqXaVwrdC2dljzET4ADSBsBLcEtbLpUJZRDv4Xq1HTxQ6eP1 PZ6g== X-Gm-Message-State: AEkooutB/Cof/hy0WXtTGnIOBGWWuRrlG8CqB9H7gxbSnoXCulSsBINZc6l8d3+BGnM92NOKyhmR/uKuV2WQTnJ0 X-Received: by 10.55.94.135 with SMTP id s129mr33536310qkb.139.1469576393004; Tue, 26 Jul 2016 16:39:53 -0700 (PDT) MIME-Version: 1.0 Sender: me@daveyshafik.com Received: by 10.237.55.138 with HTTP; Tue, 26 Jul 2016 16:39:52 -0700 (PDT) In-Reply-To: References: <2a035597d443afb282e374aead55319d@wkhudgins.info> Date: Tue, 26 Jul 2016 16:39:52 -0700 X-Google-Sender-Auth: Tie97K0qQ-TmNGS9YjL2AnQx418 Message-ID: To: will@wkhudgins.info Cc: David Rodrigues , PHP Internals Content-Type: multipart/alternative; boundary=001a114e72e4e034650538926ad7 Subject: Re: [PHP-DEV] RFC Karma Request From: davey@php.net (Davey Shafik) --001a114e72e4e034650538926ad7 Content-Type: text/plain; charset=UTF-8 Will, Now that we have generalized support for negative string offsets you can now just do: $string = "/foo/bar/bat/"; if ($string[0] === "/") { // fully-qualified path } if ($string[-1] === "/") { // trailing "/" } This avoids the overhead of a function call, arguably is as expressive, and a lot more functional (e.g. offset -2). - Davey On Tue, Jul 26, 2016 at 2:27 PM, wrote: > Thanks for replying David. > > Thanks for the questions, its good to elaborate on things some. I'll > address each question here: > > 1. No, I guess this is my first time reaching out to the community. I had > gone with str_begins and str_ends because it fit some of the current naming > approaches. I could see an argument for strstarts/strends, > strbegins/strends, or startsWith/endsWith. I'm flexible with the exact > naming. > > 2. I don't think performance-wise it would be a big improvement over using > strpos, preg_match, or substr. However, I think it might be an improvement > readability-wise. Right now people either use somewhat confusing code, like > strpos or substr, or they implement their own user-defined str_starts > function. I think the benefit in terms of readability and usability > justifies the addition of two new functions to the namespace. > > 3. This functionality is doable with the current implementation. However, > part of the goal of languages or tools is to make it easy to do common, > routine tasks. Python, Java, Ruby, C# and JavaScript all provide this > functionality. So I am sure people would find it useful in PHP. > > 4. Right now, the way I have it implemented, it is case-sensitive. If > people wanted, it could be implemented to take an optional boolean > parameter called case_sensitive which defaults to true. I could make that > change pretty easily, if I did that the function headers would be: > > boolean str_starts (string $str , str $search_value [, bool > $case_sensitive = true ] ) > boolean str_ends (string $str , str $search_value [, bool $case_sensitive > = true ] ) > > I like the idea of doing that instead of having separate, > case-insensitive, functions because it helps keep the name space less > cluttered. > > I hope this has provided some helpful information. Please get back with me > with your thoughts. > > Thanks, > Will > > > On 2016-07-26 16:09, David Rodrigues wrote: > >> Questions: >> >> 1. >> Have you talked with this list about the terms of you suggestions? >> (like str_begins, str_starts, strstarts, strbegins, str_ends, >> strends...) >> Is yes, sorry, I do not received this topic before. >> >> 2. >> There some valid performance advantage over strpos()? >> >> 3. >> And about the "market" for this new function? >> I mean, about users really need a new function like it on core. >> >> 4. >> And about the case sensitiblity? >> Should have some function like stribegins() or will be an argument? >> >> In general, I like this implementation, but I like to know about you >> in this questions. >> I don't know the policy about implements new functions on "str namespace". >> >> Thanks! >> >> 2016-07-26 15:41 GMT-03:00 : >> >>> Hello, >>> >>> I would like to submit an RFC for adding a str_begins and str_ends >>> function, >>> in relation to https://bugs.php.net/bug.php?id=67035 and >>> https://bugs.php.net/bug.php?id=50434. I've added those functions on my >>> local PHP copy. I would like to make an RFC and a PR for adding it to the >>> core PHP copy. >>> >>> Thanks, >>> >>> Will >>> >>> -- >>> PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > --001a114e72e4e034650538926ad7--