Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106204 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 5691 invoked from network); 10 Jul 2019 13:00:21 -0000 Received: from unknown (HELO mail-ed1-f52.google.com) (209.85.208.52) by pb1.pair.com with SMTP; 10 Jul 2019 13:00:21 -0000 Received: by mail-ed1-f52.google.com with SMTP id i11so1666692edq.0 for ; Wed, 10 Jul 2019 03:20:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=3s5BOvvfMCWqCf8eRZOH4Qj/AbwgrpPnn8KzJtR2PDA=; b=X82PNnzqSxm125RaUi8aujyyaZdIQzoTxfs77j4EAGkcDavdRTXBW+5IaQ8dFGSAWD MhlM7mX354uSOHRQ5Wo/931twcWkZg8uG0K4QMLBFWupvSIZJlTYM/t/sG3B2YIdq/yA zGXljFR4x4ucAG3Mg4UxBwIPyYzHM5M9qYC3ewayvUWlLD6hUryn6q1WjXHiUSHOIfS5 t3jh9Aala/RPTrjuoXMU5KS8mgzSiBMaLNESp3a1QeIY9wgz+BiCXYLfVLh3zQtV2OHb dF8LnkqyCXg3zP5gef4aoFdFcKKNEzUWfIHU7MYMuXbjKGKMWRSpj3Gajwxa6btNRt2+ Je9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=3s5BOvvfMCWqCf8eRZOH4Qj/AbwgrpPnn8KzJtR2PDA=; b=Q7BZwOrdcXqtfoVJWj1+z0c2I9U4fcj7mIKUVsd/5YfoU/RhA0f6gRrtX9iOSwF4Yw Rj2qzpsQiwmmU7PaVC0q8iSXwl4yvmMM5xAadoPu3sTx2x+erwZXazu9gbE7eLp2Ug8k 2YQI+WV5NUjcP9hrmrKNaLmeE3A2V9PmG+/blmqww+YXTz1oKuQNYTa84DDj5rw7Hn0v 5Pxcf3udpqZT8WwH/7X9UPQ0TcJdMcAulZyNpLssJpLr5chJ81EHb+x4uJ3LPc0+q7EE PGRTSBMhzyTQSfIgswLhshZ5ge+trNENajrQNsJd1x4mqO8Mzji1r0ZHcGA9f0XG4F/U slyQ== X-Gm-Message-State: APjAAAXFKj/2iYoPOiTQ+nQEiHsVzC5/SmUjJvAmx7agKBNzHAQzZrF3 KVdIwWcUBr799chdfO0HVwFLhcWbuBg9dQ== X-Google-Smtp-Source: APXvYqwHrB6MJCZ3hhMFd2wNlf+XZCYFZsSDNveGdFXj69nhGbnCQJBXc5nnyt2hdWs+OJg/BROEyQ== X-Received: by 2002:a17:906:e282:: with SMTP id gg2mr9450886ejb.38.1562754012849; Wed, 10 Jul 2019 03:20:12 -0700 (PDT) Received: from [192.168.0.63] (84-75-30-51.dclient.hispeed.ch. [84.75.30.51]) by smtp.gmail.com with ESMTPSA id q13sm552191edn.92.2019.07.10.03.20.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jul 2019 03:20:12 -0700 (PDT) Message-ID: <02D61D03-2E07-4043-BA23-A111EA06F452@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_E4AA65F3-B7BB-435B-A958-E828743990F2" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Wed, 10 Jul 2019 12:20:10 +0200 In-Reply-To: Cc: "Christoph M. Becker" , Andrew Gromov , internals , Marco Pivetta To: Andrey Andreev References: <1562591120.659818.23020.47476@mail.rambler.ru> <7ff385f1-b86d-e56d-4133-e2f101afa13e@gmx.de> X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_E4AA65F3-B7BB-435B-A958-E828743990F2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 8 juil. 2019 =C3=A0 18:52, Andrey Andreev a = =C3=A9crit : >=20 > Hi, >=20 > On Mon, Jul 8, 2019 at 4:54 PM Claude Pache > wrote: >>=20 >>=20 >>> Le 8 juil. 2019 =C3=A0 15:20, Christoph M. Becker = a =C3=A9crit : >>>=20 >>> FTR, there is already substr_compare(). >>=20 >> `substr_compare()` (as well as `strncmp()` which I am currently using = in lieu of `str_starts_with()`) forces you to provides the substring and = the length of the substring, instead of just the substring: >>=20 >> substr_compare('foobarbaz', 'foo', 0, 3) =3D=3D=3D 0 >> strncmp('foobarbaz', 'foo', 3) =3D=3D=3D 0 >> str_starts_with('foobarbaz', 'foo') >>=20 >=20 > The existence of substr_compare() and strncmp() is also my main > motivation for voting No, though I also share Zeev's reasoning. >=20 > You're right that the 2 already existing functions are a bit less > convenient to use, but the RFC doesn't even try to make a case for > that, so how do we know this was even considered? While I'm not > against having more than one way of doing things, I do think we need a > compelling enough reason to add a third way of doing the same thing > and here we don't even have an attempt to convince us. >=20 > Cheers, > Andrey. The current existing solutions (using `substr()`, `strncmp()`, = `substr_compare()`, `preg_match()` or whatever) are sufficient=E2=80=94and= may even look elegant=E2=80=94if you use them once in a blue moon. But = if you happen to use them frequently, you=E2=80=99ll find soon that they = are cumbersome and error-prone compared to the prospective = `str_starts_with()` and `str_ends_with()`. Concretely: * Each time I write `strncmp($foo, "bar", 3) =3D=3D=3D 0`, I spend a few = seconds to double-check the number of bytes in "bar". * Not later than yesterday, I spent one minute in order to find why = `substr_compare($file, ".css", -3) =3D=3D=3D 0` didn=E2=80=99t do what I = meant. Note also that the alternative `substr($file, -3) =3D=3D=3D = ".css"` suffers from the same issue, and that the alternative = `preg_match('/\\.css$/', $file)` requires you to not forget to escape = special characters. Checking whether a string begins, respectively ends, with some substring = is a relatively common task for some programmers. The issue is that, = although they have already plenty of ways to do that, none of them is = natural and all of them have issues. But indeed, the RFC text fails to discuss the various existing = alternatives and their downsides. =E2=80=94Claude --Apple-Mail=_E4AA65F3-B7BB-435B-A958-E828743990F2--