Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129481 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 6F6E31A00BC for ; Mon, 1 Dec 2025 14:26:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1764599178; bh=6M9i22nM7Vss5k4Y2uJeVXCJZ0zDV3aOHbPtFHUbkSM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=icea8vHrheeCaLZ3wN4HRO+WKSQjEQL3fao/6qncTkuhtAX04faKa4OZbywpqEp9N Sm9BIxbJsy/5gZXmO/CKfR13F9H6cDUF8LlA25mN/FcgLFE8PS8d+AFcXnZV/8WNam j+7JqazcQvH/qd2FYTeapzsHwyQBiGw/nSSAo/hvHCm/MWPrvlKXpsnq9YqVzkNu/O pEQBm8bJeAnc2FIZj9bLJ5VcZzUZ9s5VwmS/D4YNEh4J021YtHYY84KU88qSTGpC0H LsvmEj7F6YABHHlv/Y9a2KfypN6kBxhyBvXQRqF0XLjP+5gV2YWMoNaEN924nSW5wE fkWpmtzG7FDqg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C2B3B18007E for ; Mon, 1 Dec 2025 14:26:16 +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=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 autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No 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 ; Mon, 1 Dec 2025 14:26:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1764599169; bh=6ipPgxWjj4KXG3wWGLoep7BMcP/x+HPh+zk2X9uuRaI=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=gPTnMmsqO19vo7c+fiHxxbK1o0qLB53VTF/yD5cyjWSXZv/EQB2u577+F0BSxRJOa R7OXxsrKviAytEmSUPsU3vCA7NCSO0RCgQx+866pYkSXR/Hy70G8OOwn5HnMSaMq07 rlNbCwMES2qce+v+kKYfq7hFGRNWDejD8aIHCSZ99bjchjEIvuiyFn3QrVGP8TOxTA bguu53DD5279LZjolF1IL0q3egOa0sDEOq/vX8lF2CgLt5pJigxaZgkVTCohjuAYmO N+uGpPXW264K54NBfhYnzrnKPcAd4WfVYwPA5usKk7r35XX9eRmM+SqgzXM8dl71qU 3g8xAFZA72LUw== Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 01 Dec 2025 15:26:08 +0100 To: Larry Garfield Cc: php internals Subject: Re: [PHP-DEV] [RFC] Context Managers In-Reply-To: <74abada6-cb34-490e-abeb-517e39b3ffa0@app.fastmail.com> References: <74abada6-cb34-490e-abeb-517e39b3ffa0@app.fastmail.com> Message-ID: 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-11-09 16:07, schrieb Larry Garfield: > Bob, you seem to be focused on the "manual call" case. That... is not > a case that exists. I cannot think of any situation where a user > creates a context manager and then calls enter/exit context themselves > that isn't a "stop that, you're doing it wrong" situation. See my sibling reply to Rowan (https://news-web.php.net/php.internals/129468). > By the same token, you *can* implement Iterator and then call current() > and next() and valid() yourself... but odds are you're doing something > wrong, and it's very easy to screw things up if you call those methods > in the wrong order or too many times or whatever. If you implement > Iterator, you're supposed to use it with foreach(). Doing anything > else with it is "well technically that maybe works, but please don't." You are wrong here. Manually interacting with an Iterator is not just safe, it is also necessary for some use cases. The simplest example would be iterating two Iterators in lock-step (i.e. doing a `zip()` operation / array_combine()). > As Rowan noted, calling __construct() or __destruct() yourself is also > possible, and can cause things to go sideways, and if they do then it's > your own damned fault, don't do that. > > The same is true here. Someone manually calling enterContext and then > not calling exitContext() is... simply not a use case that matters, > because there's no good reason to ever do so. The only effort the RFC > needs to make in this regard is say "don't do that." See sibling reply for an explanation how `__construct()` is different. Best regards Tim Düsterhus