Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120099 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 89464 invoked from network); 21 Apr 2023 10:45:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Apr 2023 10:45:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2FE2D1804A9 for ; Fri, 21 Apr 2023 03:45:51 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 ; Fri, 21 Apr 2023 03:45:50 -0700 (PDT) Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-51b33c72686so1539555a12.1 for ; Fri, 21 Apr 2023 03:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682073949; x=1684665949; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=08v84wV0/YNJZxlSjOF+oe7PehW6eVGmss1CT24XBtw=; b=KtWznYoGDPPc5rsqUdczBH/UDSDP5i5HNj5OE2niSuei68Q8whBDwjN0IL461SFLqd zKS8C7+OouekzwFenIq9E/Mi5SPvI92L0si9ixymVUfF+N4V7trxrEBbQF9tYitzCvfG oASm/kX0dVXIpdQ2IbPS25wMNJS0Q+QHLH1pBKWzdwT6JDwz1eHTb/yvj3uT0HOvwcML f7zweCTpqHbbhfvEc4vTukCh7qSKIyrKd30paFsNHHa/YXcZca3TxwscK0LS6CEVhkE8 9R5P0jMD6eajaRpwNj80iugu36d9Dk01d7y7UBoOS3siMt9scgHU994neYyV79g/p2OA 3gNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682073949; x=1684665949; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=08v84wV0/YNJZxlSjOF+oe7PehW6eVGmss1CT24XBtw=; b=dF62JAfkcLeKjlqdPODymIB7D0cG6l8Q6EFL4Rpu+WHNcxJpcfq/5lgs4f1uhb2R3/ Zcze3DAYnKUsiq4GI+Rc3eZgh1mtGtu4AfkCvyeDMzx+GJjcWKW19S82qEDyvLBrVUgg 53orzJo1zEvbdNHtP+8MFxwQ4aJovig0yr0tVNehO4ollolP/IbjgiogwrUQafmVr7bH kmpV1UTQQ/T1VIa8zVldKR8+tM1uXqnvn1yxT8D42BTYb+Aj7IfOj5faaqtQ/crVADm8 J74cOVFLdQOGoiNquGE9kVOcSdKicaMLZBl0ZOvHcKZ1g33hYO+Y16wmtKznzXI1aOHF rmLQ== X-Gm-Message-State: AAQBX9fEhus02yp7nPBCG6hFmZ9l+mEjIF1nDKNoUFLKN9GG0stF9W1G hytbS2KG5Oj5p0BSSnRLj3p8wnqzHU7QRRrYREA1F3aU X-Google-Smtp-Source: AKy350b9LS1SlOaO0LaGINLsdJSjc0k2a+Clpd+ZwqMeQ+rLJc2jl05Lm4Hsq7w3PT6s9CsIJCtdEdppNuusllkD2r0= X-Received: by 2002:a17:902:7c17:b0:1a6:4b60:3195 with SMTP id x23-20020a1709027c1700b001a64b603195mr4484512pll.66.1682073949310; Fri, 21 Apr 2023 03:45:49 -0700 (PDT) MIME-Version: 1.0 References: <6b5de716-d769-4f0b-b3e6-5a5a211f035a@app.fastmail.com> In-Reply-To: <6b5de716-d769-4f0b-b3e6-5a5a211f035a@app.fastmail.com> Date: Fri, 21 Apr 2023 12:45:38 +0200 Message-ID: To: php internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [Discussion] Callable types via Interfaces From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Larry and Nicolas! > https://wiki.php.net/rfc/allow_casting_closures_into_single-method_interface_implementations > https://wiki.php.net/rfc/allow-closures-to-declare-interfaces-they-implement > https://wiki.php.net/rfc/structural-typing-for-closures > > What we propose is to instead lean into the interface approach. Specifically, recall that all closures in PHP are actually implemented as classes in the engine. That is: > > $f = fn(int $x, int $y): int => $x + $y; > > actually turns into (approximately) this in the engine: > > $f = new class extends \Closure > { > public function __invoke(int $x, int $y): int > { > return $x + $y; > } > } Just to comment on the technical aspect, I don't think this is accurate. Closures are indeed objects, but they are all instances of the same \Closure class. From what Nikita said in the enum RFC, objects are optimized for size, classes are not. Having different closures implement different interfaces does mean they probably all need their own class, or type checks need to account for closures in some alternative way. Ilija