Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106159 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51624 invoked from network); 7 Jul 2019 23:26:38 -0000 Received: from unknown (HELO NAM02-BL2-obe.outbound.protection.outlook.com) (40.92.3.48) by pb1.pair.com with SMTP; 7 Jul 2019 23:26:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ALf36LlUeLZG8FJ5qOZD4Wjhjxod7FCYYLnp4ZABhKU=; b=b3uTf6JrTvhj/O+Xf3p+Z5gQyOMLnJK4zxOfEDvrNNcZKV4T99G/XvzXA1/Y3hPuqcDpSLrNZWOrtQA2nPqt9NyvHAyzZdSLV3s1NQF4hNy5BExsAoJN0XLu7lXLjT5MzmQtr4wMgKrlA0b4MUxnZbXj8EMbl7T4Mv0jE8xOrATNsYNSekKePxHxofMCMYTFhqIYCF/sUorjJuzvG9y6MmMRh4FlgTiiobVQnxpVRL1mj9aOCBwtYbc+NaB1IckJOJfMl4FYu+pPMadaiV0Xvm8B288PagllFhXS2K4eTor/2KI9wYD1Cbjdhqv5Nf3gpUx3EU+pq5Vz2oD6jSckXg== Received: from CY1NAM02FT057.eop-nam02.prod.protection.outlook.com (10.152.74.57) by CY1NAM02HT063.eop-nam02.prod.protection.outlook.com (10.152.74.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2032.15; Sun, 7 Jul 2019 20:45:51 +0000 Received: from DM5PR06MB2857.namprd06.prod.outlook.com (10.152.74.60) by CY1NAM02FT057.mail.protection.outlook.com (10.152.75.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2032.15 via Frontend Transport; Sun, 7 Jul 2019 20:45:50 +0000 Received: from DM5PR06MB2857.namprd06.prod.outlook.com ([fe80::48cd:8998:c8ff:1f79]) by DM5PR06MB2857.namprd06.prod.outlook.com ([fe80::48cd:8998:c8ff:1f79%9]) with mapi id 15.20.2052.019; Sun, 7 Jul 2019 20:45:50 +0000 To: "will@wkhudgins.info" , 'PHP internals' Thread-Topic: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions Thread-Index: AQHVMtc2W38yFGmQ7UeluZx90vX1fKa/mvqi Date: Sun, 7 Jul 2019 20:45:50 +0000 Message-ID: References: <8442f1fa5544b2ca03e7cebbc64e8e5c@wkhudgins.info> <683c5da474e13283030cac3d0c0ec080@wkhudgins.info> <2c37999d1e5372ae6ab48bfce5420796@wkhudgins.info> <2CF672F8-12F5-4D37-8B8C-591A6E695220@benramsey.com> <78034520cdb610d923e25d47ed718938@wkhudgins.info> <000a01d52e91$2a4b6f20$7ee24d60$@jhdxr.com> <93528f103c149b7c48e8f35914049d06@wkhudgins.info> <97884add-88fd-e09e-92c6-2c1b68c579f5@xs4all.nl> <22ac19ecaf897370facfe9fd0a8b1993@wkhudgins.info> <0f8ab2d1-c308-7168-0aba-a5bcf327c3ad@telia.com>,<4d340e64db8d81f47cd7e4f7d3a4c268@wkhudgins.info> In-Reply-To: <4d340e64db8d81f47cd7e4f7d3a4c268@wkhudgins.info> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:ECE80AE576FDC683BCD74B13A09B19F6A0F726C5D5315B01A77B7AD4A3860348;UpperCasedChecksum:8EB1FD06DA3FBC2FC3B1DC3CF2ADC77E6704574B9548337F39862391165E292D;SizeAsReceived:7626;Count:43 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [Y2vI1xR9o+rWOwlObu3vlqUHHXSWP9RF] x-ms-publictraffictype: Email x-incomingheadercount: 43 x-eopattributedmessage: 0 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(5050001)(7020095)(20181119110)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031322404)(2017031323274)(2017031324274)(1601125500)(1603101475)(1701031045);SRVR:CY1NAM02HT063; x-ms-traffictypediagnostic: CY1NAM02HT063: x-ms-exchange-purlcount: 1 x-microsoft-antispam-message-info: V0E3jn6GpFcEylY/8A7nIK/oJsMXogK1ct6BIXCI8lA61RjgOJUCiWcO88o/DqQJoOB00rwjlaUyVWJcGXks+ZjVRtvFLenEd/gh39+HjLqNNZxsH0e3H9NSs05cKuHn5rkA60c1LlyVaX05bNkCs48fZHD8oijXIuNKodRqYVGfrr5x/YE4Qo5tUtvvjgkS Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: bf7523bb-13ed-4eff-bcb3-08d7031c1903 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Jul 2019 20:45:50.8686 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1NAM02HT063 Subject: Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions From: theodorejb@outlook.com (Theodore Brown) On Thu, July 4, 2019 at 9:13 PM Will wrote:=0A= =0A= > Hello all,=0A= >=0A= > After 15 days of discussion I have opened up voting on the following=0A= > RFC (https://wiki.php.net/rfc/add_str_begin_and_end_functions).=0A= =0A= =0A= Thank you for your work on this. I'm surprised that so far the vote=0A= is so controversial, with 8 votes in favor and 8 opposed.=0A= =0A= For those voting against adding these functions, can you clarify why?=0A= Do you dislike how they are named, or do you not see the need for the=0A= case insensitive versions, or is there an issue with the implementation?=0A= =0A= Personally I'd find the basic `str_starts_with` and `str_ends_with`=0A= functions very valuable. Currently I either have to implement functions=0A= like this myself in almost every script, or else write repetitious=0A= code like the following:=0A= =0A= ```php=0A= $needle =3D "foobar";=0A= =0A= if (substr($haystack, 0, strlen($needle)) =3D=3D=3D $needle) {=0A= // starts with "foobar"=0A= }=0A= ```=0A= =0A= To avoid repetition, many developers use the following pattern instead:=0A= =0A= ```php=0A= if (strpos($haystack, "foobar") =3D=3D=3D 0) {=0A= // starts with "foobar"=0A= }=0A= ```=0A= =0A= However, with longer strings this becomes far less efficient, since PHP=0A= has to search through the entire haystack to find the needle position.=0A= =0A= If this RFC is accepted, these awkward and inefficient approaches=0A= could be replaced with straightforward and fast code like this:=0A= =0A= ```php=0A= if (str_starts_with($haystack, "foobar")) {=0A= // ...=0A= }=0A= ```=0A= =0A= Please vote on the RFC if you haven't already. Clarification would be=0A= appreciated if don't feel that these functions would be a good addition.=0A= =0A= Best regards,=0A= Theodore=