Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109778 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25299 invoked from network); 22 Apr 2020 17:58:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Apr 2020 17:58:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EC77E1804F8 for ; Wed, 22 Apr 2020 09:30:18 -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=-0.6 required=5.0 tests=BAYES_00,BODY_8BITS, 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 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-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 22 Apr 2020 09:30:18 -0700 (PDT) Received: by mail-wm1-f47.google.com with SMTP id r26so3153993wmh.0 for ; Wed, 22 Apr 2020 09:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=VyarkBIFzPereRXNKD9HUkbP7TMs9/FupwSFbqOCpkk=; b=fpyIXkbLqSToHH9yxtgU1d/zuo7Yr5i1sW9JQCf/z4TepDRZOeeff0wvFuu+KbSbJ4 as5RfcQNoRZ9z66TQbNqYv3JgHbT6wmhTmutDfySsz7ezcmoCXbXOLIHxKywLbsoF9z9 zINgP5mavVqTr4S8TJDFhyE6nw62/rp4B89NUtHroJJt7iGsPSw5lU/sP3vQLKpxRxuc KSBEpqwxDZ5cmxvoCkAP7cfKK1qERgV0fxAsZQPYk6uP/Qp6fdd8US37L1/TSnCGJ2ys cVUtq1VdXvNwiOe+A817YJSQh8Bkb91xuqpt09LM59IuZHyUibd4N8j4aUtyOONd7/Z4 yDfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=VyarkBIFzPereRXNKD9HUkbP7TMs9/FupwSFbqOCpkk=; b=Q3eXyYgbABTBzg4JdS0JspKBVlOPnY6t6Nu+wxlyGEEnntSLTPau6ZwoMb6YMKzmck S2/1LDCD0cVbPkH6UMUu0Mj9pZytoaDsclCuG+3Dsqz5Aw2o+ELeBxGzVYFxORogDyCv N9iaitus8ep2rhB1GBy5ZdZc5/wcMiAl3oihUAaULw9BbcBg+t2DqOQmpCs8TC5YpZjJ lpCXtzpdFac3mdkk507I08BHRQdDg/hiovhc18p/RSgOhmwNLKQg/oYhU7Zi99iSg/yN dQQOiCSGODXrDEu+7AvEd8mzZeAdiXmIuNkmw+EpfVoaMsVeVq8+jQs365djti6MgCuZ e0aw== X-Gm-Message-State: AGi0PuYbLgkUzBCRophGTx9jpVwPCfg7nbxMTPzHUtpnIsHcesX4096n MqLvYhIv87ylXtXBLRiz7sbPwczP X-Google-Smtp-Source: APiQypKl5bTmxWiPNz9Gi3aRli0rO5nEAFkgPXU4b0YXWb207IWUmj2lrzJk5hA/h2x0vzeo80aPXQ== X-Received: by 2002:a1c:bd08:: with SMTP id n8mr11276008wmf.23.1587573013545; Wed, 22 Apr 2020 09:30:13 -0700 (PDT) Received: from [192.168.0.14] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id c190sm8767180wme.4.2020.04.22.09.30.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Apr 2020 09:30:12 -0700 (PDT) To: internals@lists.php.net References: Message-ID: Date: Wed, 22 Apr 2020 17:30:10 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] Typed callable properties From: rowan.collins@gmail.com (Rowan Tommins) On 22/04/2020 16:01, Michał Brzuchalski wrote: > I agree, a callable brings as much information as a resource type - you > know the type > but are unable to use it without additional information. While this is true, it's somewhat orthogonal to the question Benas raised in this thread - namely, how to handle values that are callable in one scope but not another. That is, is the following code valid (error-free) or not? delegate Reducer (?int $sum, int $item = 0): int; class X {     private static function myPrivateMethod(?int $sum, int $item = 0): int {          return 0;     }     public static function runReducer(Reducer $r) {          return $r(0, 0);     } } echo X::bar(['X', 'myPrivateMethod']); The equivalent code with a type constraint of "callable" currently runs fine, even though passing the same value to a different function would fail due to scoping. Making the delegate-constrained version throw an error for any private or protected method would just trade one inconsistency for another. A more reasonable restriction, IMO, would be to say that delegates only match Closure instances (and possibly other objects with a public __invoke method), not the various string and array syntaxes that "callable" currently allows. The case above would then need to bind the private method into a closure that is callable everywhere, e.g. using Closure::fromCallable([self::class, 'myPrivateMethod']); The obvious downside is that Closure::fromCallable is both verbose and a potential performance hit. So it seems we're back again to wanting a new syntax to succinctly and optimally generate such a closure. For instance, in the discussion of ::func, one suggestion was "$closure={self::myPrivateMethod};" and more recently it was mentioned that a variant of partial application is to not actually bind anything, and write "$closure=self::myPrivateMethod(?, ?);" Regards, -- Rowan Tommins (né Collins) [IMSoP]