Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120090 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 38215 invoked from network); 20 Apr 2023 20:49:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Apr 2023 20:49:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B62B01804D5 for ; Thu, 20 Apr 2023 13:49:56 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 20 Apr 2023 13:49:56 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id AEB5D5C0175 for ; Thu, 20 Apr 2023 16:49:55 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Thu, 20 Apr 2023 16:49:55 -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:sender:subject :subject:to:to; s=fm3; t=1682023795; x=1682110195; bh=+SCJGwLn2q xflxVBdDe0wHPK+GEtvj72pY+QY1pCFiU=; b=qNf4ag/bTayiQcYSInTBdmlhwU n+0NiAL7FQc9EAke8GrzyeKdZNftqEQi7ctlILUdZugbccoQ077JukTtq0Upx/n9 ofR6CsOp3X0QFUz9qv8Nq7ZbjYb1KdhjtSYK5xxKBWhTGwcl0xcaJH9qLyqys43n 7cyLWtLY+ScEvtZnAnAlFEUkUpkZJVdEQNcU1jbgW8soQC+ZBj+/0FOJ/2OAPS4p 5+BsTcrY027Jfos7GmwFZAt0UyS3zb22Zq8Ni7M2vXZqL6fvqere0ul3IXzCpV7y +gqbPPezQFuKNL7BUxdJ8unnogy2dMtslLjv+DI0+Zjj3ug/Uuh3W515rXKg== 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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1682023795; x= 1682110195; bh=+SCJGwLn2qxflxVBdDe0wHPK+GEtvj72pY+QY1pCFiU=; b=N o/HlSn6TwCNW2+Sz8IH7x7EccYHNIy4Sj3zD+XwDlijyNmDKOUD4efrb0FYAVj9f wYQYTQXtWLHyFckQSUgLm4aFAWKkuninFfKB2avaeTUJVy06mFh9JAcUNe/OIL9q oL5po+wg/gjmMN5pNIoOCA/2gphmON6vY3MFjq5tnzvvKvgRTfuCZldtggkSEm8i H+2R3rUxpL0hwnrUWkqsy61yjMH1XKrBdVPS1WfPuTsalDE+ApCbecpHmzC8IAWi LyzfLy/6FvfZJp5Fo22RfBofzVlDmg6venxR8IcsNbxLjv08tRKwDYGj/vgb14z4 zQqpJZ+QwFTZe4gg4iPcQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfedtvddgudehfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfn rghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrd gtohhmqeenucggtffrrghtthgvrhhnpeffffffjeffudfggeevvdeitdetvdfgjefffeff jeelfeejteevheeghffhvdfgleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 615FA1700089; Thu, 20 Apr 2023 16:49:55 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-372-g43825cb665-fm-20230411.003-g43825cb6 Mime-Version: 1.0 Message-ID: <4afc6a53-46c8-462a-a735-a2509023a589@app.fastmail.com> In-Reply-To: References: <6b5de716-d769-4f0b-b3e6-5a5a211f035a@app.fastmail.com> Date: Thu, 20 Apr 2023 20:49:35 +0000 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [Discussion] Callable types via Interfaces From: larry@garfieldtech.com ("Larry Garfield") On Thu, Apr 20, 2023, at 8:26 PM, Micha=C5=82 Marcin Brzuchalski wrote: > Hi > >> There is one loophole, in that an interface may require an __invoke() >> method: >> >> interface TwoInts >> { >> public function __invoke(int $a, int $b): int; >> } >> >> > I was playing around with the code and parser for this in 2020 but my = idea > was to introduce a new syntax that is inspired by C# - Delegates [1] > > delegate Reducer (?int $sum, int $item =3D 0): int; > > class Foo implements Reducer { > public function __invoke(?int $sum, int $item =3D 0): int { } > } > function reduce(Reducer $reducer) { > var_dump($reducer(0, 5)); > } > reduce(new Foo()); > reduce(fn(?int $sum, int $item =3D 0): int =3D> 8); > > At the same time, I assumed structural typing for closures would be us= ed. > I assumed the delegate will resolve into > interface Reducer { > public function __invoke(?int $sum, int $item =3D 0): int {} > } This is effectively the same as the "typedef" version of callable types = from my email to Dan a moment ago. See there for the challenges. --Larry Garfield