Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123944 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 qa.php.net (Postfix) with ESMTPS id B015B1A009C for ; Thu, 27 Jun 2024 17:08:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719508217; bh=+53lVVHE6fsHvpoieTs7sLA5/ZhjXLhE7qGkyrH2aDM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=l/Fwjj5MsY2X72/Uxd16L0FCA6rxrIYewMnng73KHQLeNDRwEKnHe3nyw2BXCzv4Q Ueyu/+SCERrc3RIU8hDSrzVHIT3nLn/mao8iIOD+9apAbWSZVGwI9Momxr4m8SuwTF G6+Md8ixKQm0QiDsX/+EfgAvTHIT6E0NTCnMcO49FOG5SLvUKClVhM8jRFcFIhODx+ 1ekfKYqbLP3Zo1hey54LI2xjxxnKiPuTsFlxDDVEyZeeNMeYKYI1yRQ1SFhYou++W6 hQb84ONu/nAq4UNpcMDtucDO9JbASNiZROOJd6TkmA9gSdjdClO6gQUoPkf02wP7xV mXh1AgjtKmxsA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BAD9E18070F for ; Thu, 27 Jun 2024 17:10:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 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 ; Thu, 27 Jun 2024 17:10:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1719508136; bh=gHmdctVfcu8+3GAzpMaW/1E7Ql5M/iCf7iCTw7tGzcw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=jV5vIbTJxmVauucADvGE0+4kHzuFh2JBkBuUfpdXLezWi7sdFL+9rVMjo31OR2Pnf bqAOxhVlfH3SfmydnNyvoqoItZ1Y9mCLZ/S1/E/JIpZdBFBaKJUPVl+iaVwiUWhyXE XMqUvSu1iwZXNZW9HvNU11uDvS+/abny/IdOvA1XzR+WJgm8AR2I70P48EFZrGDqAv LWjmef+noUyx32P7klo8D+K0pMsNz/McGF+Iv5psCeKIpTfdXxs7LNRqK9vZBE60lG PjT7OQN/Ca5m9J4+uhihguzkXAtazypkWBPducTvsbMGHR/wgzbteCoqWaTBtPP8xs St/EM+J0DI4kA== Message-ID: <6a7c17d0-011f-413c-b7d6-23ea0019e151@bastelstu.be> Date: Thu, 27 Jun 2024 19:08:53 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] Deprecations for PHP 8.4 To: "Gina P. Banyard" , Mike Schinkel Cc: PHP internals References: Content-Language: en-US In-Reply-To: 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 On 6/26/24 14:14, Gina P. Banyard wrote: >> Regarding explode($delimiter, $str)[0] — unless it is to be special-cased during compilation —it is a really inefficient way to find the substring up to the first character, especially for large strings and/or when in a tight loop where the explode is contained in a called function > > Then use a regex: https://3v4l.org/SGWL5 > > Or a combination of strpos and substr. > > I'd bet that both of these solutions would use less memory, and I would guess the PCRE one should also be better for performance (although not benchmarked) as it is highly specialized in that task. > > There are *plenty* of solutions to the specific problem you pose here, and thus many different solutions more or less appropriate. FWIW: `explode()` also has a third parameter to limit the number of segments to return. If you always want just one, you can set the parameter to `2` to prevent further processing from happening after encountering the first delimiter. Best regards Tim Düsterhus