Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108648 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 88406 invoked from network); 17 Feb 2020 15:22:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Feb 2020 15:22:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A3D541804D6 for ; Mon, 17 Feb 2020 05:38:07 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 17 Feb 2020 05:38:04 -0800 (PST) Received: by mail-wr1-f66.google.com with SMTP id u6so19827414wrt.0 for ; Mon, 17 Feb 2020 05:38:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=yFOpVMjYFPCTIg4Tb63sml9yMKvv816RtsOWfhnOoaM=; b=lxAi40Rs7wlGzG699jjz4EUoM2GX6SJBs508nqJ8hsGxF5Nk4EkyBHs3zbDm5ZnbPA GKyKT3XCvQz8FATA1z/4Q/IXzIb9Httdm80Oko7xezJ3gimXMYs4gG3hNGLvI0rI4E2d Jke2vmOxnE22+oC3xReE5i7OkC9+D9uTJJjCD/npr8HALaCwMMQgEdhWwPaVBoHfZp/V xWyltLGQnOt7cDgr0+Ed0zRQOSVUFB+TE0320Bjq0jyHcOMfe54cgFgePmulPsgGOR6x MLsQZX3yN1dclXivVOfPSUXK/5yJ1pviwcVMm1E7n64wt7RdtuDIB++c0GSi5ZVHaMn+ Yxow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=yFOpVMjYFPCTIg4Tb63sml9yMKvv816RtsOWfhnOoaM=; b=QDzoyp7+SeAC5IzghjnPPBVO4J9rbTuPx2irhtwPTS29LALkCSt9Tkb+cs5To9FSqH vfVaqzDLW12LH2JAbUMPAzU8rL0t18pUX+IYsJFHea+s8gkjHRz+//lwEhSgpAj43ApV 5cOzvmni6liKaKKKq8ccIfSVpuR7fqfABqdXp9ZrJ2MX0Wq9YVbjgNgPTQdShtI9eTN+ 7c5Ru5w8dyBBi7MfVcv6CV2CMwMky4YeF5Dh9ykpg0baLP9yXlci/iqmoI70hBj0fcYb RTlC6vStYzcYJLZ20EYQVKabyob8xHkW5P37nR7PCn2cPxsqebf6Ivb7y+Nji/guQWkG mJkA== X-Gm-Message-State: APjAAAXM8+BioEBbHxjb+U8LPxeyQ7opEuDKHJ7H+sH/xRO6Vkq6Qg/2 dyD38myooDaV4ToX5/NgY7cmwCjL7GNxqToekjQ= X-Google-Smtp-Source: APXvYqyDo53pqtRbobZxD3MM68payxeNFvGLPvKcmERepObPuD/82goZLtbLT0Lv9vP29uZpRV2OKYRkX1fHR8Dq3TQ= X-Received: by 2002:a5d:5706:: with SMTP id a6mr22355770wrv.108.1581946682886; Mon, 17 Feb 2020 05:38:02 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 17 Feb 2020 20:37:51 +0700 Message-ID: To: Nikita Popov Cc: Philipp Tanlak , PHP internals Content-Type: multipart/alternative; boundary="000000000000164ee8059ec5aab8" Subject: Re: [PHP-DEV] Proposal for a new basic function: str_contains From: pierre.php@gmail.com (Pierre Joye) --000000000000164ee8059ec5aab8 Content-Type: text/plain; charset="UTF-8" hello, On Fri, Feb 14, 2020, 6:54 PM Nikita Popov wrote: > On Fri, Feb 14, 2020 at 10:18 AM Philipp Tanlak > wrote: > > > Hello PHP Devs, > > > > I would like to propose the new basic function: str_contains. > > > > The goal of this proposal is to standardize on a function, to check > weather > > or not a string is contained in another string, which has a very common > > use-case in almost every PHP project. > > PHP Frameworks like Laravel create helper functions for this behavior > > because it is so ubiquitous. > > > > There are currently a couple of approaches to create such a behavior, > most > > commonly: > > > strpos($haystack, $needle) !== false; > > strstr($haystack, $needle) !== false; > > preg_match('/' . $needle . '/', $haystack) != 0; > > > > All of these functions serve the same purpose but are either not > intuitive, > > easy to get wrong (especially with the !== comparison) or hard to > remember > > for new PHP developers. > > > > The proposed signature for this function follows the conventions of other > > signatures of string functions and should look like this: > > > > str_contains(string $haystack, string $needle): bool > > > > This function is very easy to implement, has no side effects or backward > > compatibility issues. > > I've implemented this feature and created a pull request on GitHub ( > Link: > > https://github.com/php/php-src/pull/5179 ). > > > > To get this function into the PHP core, I will open up an RFC for this. > > But first, I would like to get your opinions and consensus on this > > proposal. > > > > What are your opinions on this proposal? > > > > Sounds good to me. This operation is needed often enough that it deserves a > dedicated function. > > I'd recommend leaving the proposal at only str_contains(), in particular: > > * Do not propose a case-insensitive variant. I believe this is really the > point on which the last str_starts_with/str_ends_with proposal failed. > > * Do not propose mb_str_contains(). Especially as no offsets are involved, > there is no reason to have this function. (For UTF-8, the behavior would be > exactly equivalent to str_contains.) > Btw, while some mbstring references I I mentioned, I do like the ICU search implementation as well. http://userguide.icu-project.org/collation/icu-string-search-service It handles a lot of cases based on locales. > Regards, > Nikita > --000000000000164ee8059ec5aab8--