Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128907 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 4368F1A00BC for ; Wed, 22 Oct 2025 17:24:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761153887; bh=dvxOwGu4ECegWK1zSR+KBM5U1o6JLraumXQgr1ZV5+M=; h=Date:From:To:In-Reply-To:References:Subject:From; b=PuChGmywW+PMmfVNApagmjG3HAiiRpUF+b6ugg/KrzEow+Wo9D1xZHCtPci7lrSZa 22W/AS9sQzVTPc867dmg0kpbMwduJ0jWiUCIvLjJmDUwSVJMS7INse6cstcRPLgCeL ridzAEq6u0wsZOoUA11HHvnpZa6wnMGHEQNCWf/4YDAu2VJ1m++QyBYN2bnM9mPzpz oV2mOBJp2/bV3H+9MNQrZh11Ni4OR0Gw5RgV8a6cWwlC4FcGMl4VnTclkxHVMcmYko sni0x5/LKusee0o3Y1XT7YOder1isfXeiOraGvtxGJhvYYAoL6NrvMPN1QKKXCvQ6n gDQjrza2LPH/g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1C3A71801D4 for ; Wed, 22 Oct 2025 17:24:47 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b7-smtp.messagingengine.com (fhigh-b7-smtp.messagingengine.com [202.12.124.158]) (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, 22 Oct 2025 17:24:46 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfhigh.stl.internal (Postfix) with ESMTP id 2A5097A00E2 for ; Wed, 22 Oct 2025 13:24:41 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-10.internal (MEProxy); Wed, 22 Oct 2025 13:24:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm2; t=1761153881; x=1761240281; bh=o49N6SBOdyI645eGIg5/q L0MUIGJ++UZ4pzFgEzQdeo=; b=tWr7Tq9+sWzXbpHFBgQvZ33kCvU+UVO091UOv 702x9n/cQuzgDtlH3s99JGkrudJGHPM5eMGGA4QN8mKDb8aB6aIALu81Cv6DIxjG oWb//dtV0YQb8wVpyi7CgqbdYniBHT2inVWW33cDKtq/yuYzSOz8qp1QUgS68sjl s1tx9wyNY+cy8ogt+k4I1mzyGopsvPGcu4VCKZ+pxH3nr5+xfxAxoEyUdAjF711o 9+EfzWQsurDWCHlAn/7tFrHq2HA175R+WYa8hd8uCfj1VeZNdvlmLPM8SsHGcIe9 B7DKwvSqgKw7afsjtOAF6JhCXCreyKSVZQNRirtZy4C+QPooQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1761153881; x=1761240281; bh=o 49N6SBOdyI645eGIg5/qL0MUIGJ++UZ4pzFgEzQdeo=; b=hVTW0zCib6gq4Wb+C aNV2+rCgwPijVhp90KFcn9F18oXzEOutbaFH4Fok/6EVsWX/eZND5CUkxsWER1Vv iR68QwPBHd/yAmz1jkSSViqwi0y9E2bBb6fQUrxwgbeGfxtuv2/0gtBm0JwrQF6q cfEW2ZgmpYcBHn1FHmdr/s8IuM0PHUBBKUtEUKUUKN/2jjN3nqVzlyWuemWusBSU 3H38fJYTlf+pDI8LZnd1eMhpCWxwHpCrxDVY1dsJcgckrP1C6ZqX0Y1+/6VlKspK /dyPUyKMrizbAzh0YTOVTn7PUvTarAteSm2qUFRIpHsfURBBWMGCYLBenQe2Igjr QtmqQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddugeegudejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvffkjghfufgtgfesthhqredtredtjeenucfhrhhomhepfdfnrghrrhih ucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqe enucggtffrrghtthgvrhhnpeffieeivdfhvdeguddttdegteeiueegvefhteehfeeffeet udeitdehtdegjeeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomhdpnhgspghrtghp thhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsh eslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 781C3700063; Wed, 22 Oct 2025 13:24:40 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: AejB4fewBc7J Date: Wed, 22 Oct 2025 12:24:18 -0500 To: "php internals" Message-ID: <2e99b70d-1ca3-4570-a3b3-7cae9dfc101b@app.fastmail.com> In-Reply-To: References: <0e4e39d6-9cc9-4970-92e0-2463143b4011@app.fastmail.com> <37180d8d-85b4-49a3-a672-334bf4329470@app.fastmail.com> <2f8524a7-dea2-4fbf-933a-c538d3706253@app.fastmail.com> <151800a7-1094-49bc-8e43-c593a74741af@app.fastmail.com> <772a457f-69b6-4a76-8224-081917d719f6@app.fastmail.com> Subject: Re: [PHP-DEV] PHP True Async RFC Stage 4 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Wed, Oct 22, 2025, at 10:30 AM, Edmond Dantes wrote: >> This isn't even the same example. We're not talking about type juggli= ng, but an interface. Mixed is not an object nor an interface. > Why? > Type and Interface are contracts. > >> The "FutureLike" type is exactly what I'm arguing for! > > I have nothing against this interface. My point is different: > 1. Should the await and awaitXX functions accept only Future? > 2. Should Awaitable be hidden from the PHP userland? > >> foreach($next =3D await($awaitable)) { } > What=E2=80=99s the problem here? The object will return a result. > If the result is iterable, it will go into the foreach loop. An > absolutely normal situation. > >> error: multiple usages of multi-shot Awaitable; you may get a differe= nt result on each invocation of await() > Why can=E2=80=99t you call await twice? What=E2=80=99s illegal about i= t? > If it=E2=80=99s a Future, you=E2=80=99ll get the previous result; if i= t=E2=80=99s an > Awaitable, you=E2=80=99ll get the second value. > But the correctness of the code here 100% depends on the programmer=E2= =80=99s intent. And that's exactly the problem. The correctness cannot be inferred with= out asking the programmer. There is, obviously, no such thing as idiot-proof code, as the world wil= l always create a better idiot. But we should still strive to be idiot-= resistant. There are two general ways of doing that:=20 1. Affordances - Basically, it should be hard to use wrong. =20 2. Construction - It should be impossible to use wrong in the first plac= e. (Ie, a compile error.) The classic example is US electrical plugs vs EU plugs. They *should* b= e different shapes, because they're different voltages. If you plug an = unsuspecting device into the wrong voltage, it goes boom. So the differ= ent plug interfaces make it patently obvious that you're doing something= wrong because they don't fit together (construction), and if you use an= adapter that is your signal that you need to worry about voltage conver= sion (affordance). Using the same type for something that can be read only once vs somethin= g that should be read multiple times is equivalent to using the same plu= g for both 120v and 240v current. (Or USB-C using the same plug for 8 d= ifferent speeds, 5 different power delivery levels, and sometimes no dat= a at all. It sucks.) The developer needs to "just know" which one is i= ntended, because the code doesn't tell them. That's a problem. Instead, like Rob said, there should be a one-shot object that dies as s= oon as it is successfully read. That is guaranteed to be single-use, an= d reading it multiple times is detectable by a static analysis tool as "= you clearly are doing this wrong, no question." Then a multi-read object is... an Iterable that produces those single sh= ot objects. I'm not sure if that even needs its own object that impleme= nts Iterable, or if it's OK to not define it and just say it's any itera= ble. (So, a generator would work just as well.) I'm leaning= toward the latter, but there may be uses for the former, not sure. But having a "dual voltage" awaitable object is exactly the sort of foot= gun many of us are talking about. The contract is under-specified, so i= t's too easy for the developer to be "holding it wrong" and plug it into= the wrong wall socket. Boom. --Larry Garfield