Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120028 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 7400 invoked from network); 13 Apr 2023 14:28:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Apr 2023 14:28:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8522718054D for ; Thu, 13 Apr 2023 07:28:16 -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_H2,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-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (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, 13 Apr 2023 07:28:16 -0700 (PDT) Received: by mail-oi1-f181.google.com with SMTP id bm45so4327917oib.4 for ; Thu, 13 Apr 2023 07:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681396095; x=1683988095; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=U2zKZZKVpZGy4HemJyJQYx0XrAQ8THhwoOmXxBeEGRc=; b=ZHVDCKeL/oyfO76As9py5Cnvlefzq1Jke09l9Oql4gewUSGs7K7EHcQ5U5AKi3mQOH vK2PYCUIjnaLUmEKaZt6qEardt8DzLEc9rxN4FrteBvMfmy7fjenn8W9ivvLPMkdaDS9 6gKU68r5nQYT6Aeh+H7HO0hK2ea3aaLQ1gTD/wKKpW9m67ckfuQCmk+fm5RiQoZMcBf4 hq8JU00cWtgi8qjxPx8ZpI1x6N9TzLCtESsxMp9k28JCEoN9eM8VlAUGXuk01DD7PC/2 bXx/BG4Gye5dZWw6mKga3+nuNvW8MV3WbxLGCmtDX703mJHpoKrQ1BdbNTPIpmtRwbNH oWjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681396095; x=1683988095; h=content-transfer-encoding:cc: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=U2zKZZKVpZGy4HemJyJQYx0XrAQ8THhwoOmXxBeEGRc=; b=dmh1IamcH7G70XrCJa+ZDqefRy5S3rzFQwO3Lwehts0RHSpS+RhOm5No9fWevrguX5 8W5zVU3BTZ3D13i+WnYG5dCpXVJakt2tkDI07jj8sddZZmQDzfV2GgnifWsYdHI21TLa 8L7XsZE87D6ujGJshDwieTNFv89jUWGwVRDNqK3gwHtD4WLwM8Rvu/hEMMmyyr34ts5H ce1mJjXAiHs6Y1sAvAq6MhGsPChs6zIc4rP+09gatFNB4n94JQSX+RbtAqU5yIpsds7G kmyr1XFBygJNyHlM4YYcHxUi7hvTvLQI4p0Z1qCcBm6MnIzoTLDiTOXsHgHDe+jrWlq3 T7Ag== X-Gm-Message-State: AAQBX9delG9PKMs/tgvvHtj++WUKZ6hn9L35vuwwXUsfUHZ1N77ntvCf 9DICujyfjpnVOy+ErZi9jbaWyETaohGHro7lKjM= X-Google-Smtp-Source: AKy350aqAreK5tPFvZJ3HTNfe43zL1DklPp1DOh9CP+cWfpCFfJmP6T4USf44lNJTA3whTRgaaPSdJnfHzfeXlhren0= X-Received: by 2002:aca:a995:0:b0:38c:2e50:7ba1 with SMTP id s143-20020acaa995000000b0038c2e507ba1mr137978oie.9.1681396095411; Thu, 13 Apr 2023 07:28:15 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 13 Apr 2023 16:28:04 +0200 Message-ID: To: Dan Ackroyd Cc: Eugene Sidelnyk , PHP Internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] First class callable syntax for instance methods From: landers.robert@gmail.com (Robert Landers) On Thu, Apr 13, 2023 at 3:47=E2=80=AFPM Dan Ackroyd wrote: > I can't see a technical reason not to do it like this, but some people > seem to be having negative gut reactions to it, and it's hard to > persuade someone about aesthetics. > > Notes here: https://phpopendocs.com/rfc_codex/class_method_callable > > cheers > Dan > Ack I'd be down for implementing this in a heartbeat if we can agree on a syntax. I've run into this issue several times and have thought about it, just never really done anything about it. Hmm, yeah, looking at the implementation again, it may not be *that* big of a change. If I'm understanding correctly, it *might* need a new op-code (but could be done using the existing ZEND_CALLABLE_CONVERT), but otherwise should be rather straightforward. The bigger changes are going to be in the Callable implementation. As mentioned, this 'view of the world' isn't really supported by the engine. You can't perform this operation (calling a method on an interchangeable object) without another closure (to my knowledge) to do so. Perhaps we could sidestep the syntax issue by taking some inspiration from Rowan(?) and just implement this as a method on \Closure or \Callable, maybe something like this: $a =3D Closure::fromCallable(static fn () =3D> $this->getId()); $b =3D Closure::bindMany($items); // executes `bind` on each item in the array, returning an array of closures foreach($b as $callback) { $callback(); } or something like that. My biggest thing is that there's no real way to save much on typing this out. Unless you are doing something fairly exotic, you only save a few characters. That's why I said its a lot of work for not much benefit. I could be totally wrong though because I, personally, do run into wanting this feature several times a year.