Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127647 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 2E7E71A00BC for ; Wed, 11 Jun 2025 10:20:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1749637122; bh=zHelaB92enFSY+e3Vh8t4lf1HcyZ560yPhnIc3VVKKo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dIG7sdwquh3hDsbPFsJZwNyAS92+nRnBBW1PVxdnUVXOyi+S7nEQfJNUwHk1B7fLZ oyw89h58ZXO9J7diPUx/HsFnoHXzhWrYmzsN/0gO+m+nl75GgpHIWkXmnMj5HWO2gH ZnXj6FcYnt2w6K+qLYS6FgewoCksCZ532C+Atj+U56EtoFktoQe+sv68pNSU9hui4q KSXCMpHTKgId7PtJxBa1qdYYCx1lU4+oJ6ftvNo39QO6YS556FMxVQfRcZcsVjhfN2 9qytYjXojM80SQaHg4YfX1lemEZMv9npr4w3OM2J/SzpwscnPfa7Smx29sveqkDDeL KFHMe7RyPpl/Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 09C77180081 for ; Wed, 11 Jun 2025 10:18:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) 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,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 11 Jun 2025 10:18:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1749637240; bh=EGVbT2CpBhwRz9zzOiH1WZkQ2sqlSR3j35HZUs0Ma6A=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=ZgLESHRXhTCZ0IjxKJZEikEG0UcvvLpjD4VIxFZm57bhR6qHpRoofwjotArRvw74g WVziK0hGbQPGxRjGPr8gM3wHHUV4WmhL4p2tlb5oAZMAEvftjxSKLa0PKPQGdKs843 ijNkSnmb/rOGxjAWecnbjVcSTr56W+bwqDK22XCHwjRHEdkC9CqI/fyAa5bPkhxqbv GIp75YRLyGQxZakkYXYbbRPUuoC2Op9Jscjj33t1hNGARI1aRO8aC0HJAjdHmuJ+OQ OvN4e+U3aG4oCHTUcK+H/aYUXigymovxdT0yzIrWMaNKcbbAC2CZI4V7Q+IUFIX6I7 eSH9Fi7UGK3YQ== Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Wed, 11 Jun 2025 12:20:40 +0200 To: Christian Schneider Cc: PHP Internals List Subject: Re: [PHP-DEV] Can we make str_(starts|ends)_with variadic? In-Reply-To: References: Message-ID: <5c212a47cf3600f425039e76aa3d681a@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Am 2025-06-11 11:58, schrieb Christian Schneider: > Am 10.06.2025 um 21:46 schrieb Hans Henrik Bergan : >> Can we make str_(starts|ends)_with variadic? >> ``` >> if (str_starts_with($url, "http://", "https://")) { >> // url >> } >> if (str_ends_with($filename, ".pdf", ".doc", ".docx")) { >> // document >> } >> if(str_ends_with($str, ...$validExtensions){ >> // valid extension >> } >> ``` > > […] > > Which leaves me +-0 on this, > - Chris I agree that the examples are not particularly well-chosen, because the correct implementation for the two examples would be: if (\in_array(\pathinfo($filename, PATHINFO_EXTENSION), ['pdf', 'doc', 'docx'], true)) { } and if (\in_array(\Uri\Rfc3986\Uri::parse($url)?->getScheme(), ['http', 'https'], true)) { } and then leaving it up to the code developers / the engien to possibly optimize `\in_array()` into `match()` or similar when only a small number of values need to be matched. Best regards Tim Düsterhus