Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109784 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56246 invoked from network); 22 Apr 2020 19:07:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Apr 2020 19:07:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A7D4B1804B7 for ; Wed, 22 Apr 2020 10:39:21 -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,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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-ot1-f65.google.com (mail-ot1-f65.google.com [209.85.210.65]) (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 10:39:20 -0700 (PDT) Received: by mail-ot1-f65.google.com with SMTP id g14so2844498otg.10 for ; Wed, 22 Apr 2020 10:39:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ic9FNpZmkSiL1Xly19PtXjgSYraPCrajPAULV8xw3BU=; b=ZFq1iQdBaDC21dW4KeHTrSrdXLQP6RGbwL8hCsTTSlA21lw2o4ZA2heEbDzf92TQTG thv028Qq6nbUA8zqOXQ9P9//XIR1vJu4G3sMc9SfChixZ6Ag7viCjuQTSrnPIaISwFT7 1Qk7Iv9R9DlONvbyV8LAyP5jFfU+y0boWnuxC9iTVdqn9GqafJwXZtM2STyopOTHxQiU TdQPO60LSr56hhrBXgXtNQZcN93EirKqQdG4o/4NkkoAiwtv3apNX9yJwvMdgMspPgT2 7h2UFohZ97CCM16W3ICt2S6qp1HBWaXuLRg9GZBroZiW524rDZOn6ksbm64WIWaC7X5A UsJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ic9FNpZmkSiL1Xly19PtXjgSYraPCrajPAULV8xw3BU=; b=dmsqfSnhw01ybZzvG3iiIN+RsVOePf3pitjzwckMIbNAgva4jOW8la4a8QDv2ZaLiB CzgwCNR7p3Swn8Ukyvz7AeFIOc/num/xxZZpqcIkfD3X7Ue96DVGnTT7YZ9EpaGWP8J8 ZDATkPVxmmykcqKcWML1RRWKRznY8nIuH7/tblh8RnD1x1A+RqMODSTELFyCuQV2tyRW HxtGxhshaqlSy3zIKEqQbFdYTBQhGBf5mr+pHaJpkDWLlMp6jxS1DygwcL4hTwobNi8v Qa8ukk5Em126T+O7YQNUzIvKpyXNBKBpyXBjXvtPjNLocB9DmIIxvInt7l9t8x6ujP0c IX5w== X-Gm-Message-State: AGi0PubFo9w7ip6rrO6wi0hNTrnJvaEdn3VyHa81vopuXSvtTEN5ChDu fBxPbIxsxMYaI8IqimkFFXK1TTSGpFXs2tO7h40= X-Google-Smtp-Source: APiQypJUXqZuBcPMU2Ag/GGJr7gO5b5WOyg/qK0pG9Nm/DH24kgQwM4x4YPLZIIblnWHLyXXR60cMU2g0w1kzdwR7Eo= X-Received: by 2002:a9d:7d15:: with SMTP id v21mr168375otn.182.1587577157253; Wed, 22 Apr 2020 10:39:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 22 Apr 2020 19:39:05 +0200 Message-ID: To: moliata Cc: Dan Ackroyd , "internals@lists.php.net" Content-Type: multipart/alternative; boundary="00000000000082fdc305a3e49cb3" Subject: Re: [PHP-DEV] Typed callable properties From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --00000000000082fdc305a3e49cb3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Benas, my responses below. =C5=9Br., 22 kwi 2020 o 19:17 moliata napisa=C5=82= (a): > Hello, > > thank you for an opinion as well! While I do fully agree that callable ty= pe > needs to be improved with features such as typedefs, I found a couple of > problems in your response. > > First of all, I wouldn't say that the callable type provides little-to-no > information like the resource type. A resource can only be made by specif= ic > functions such as `fopen()` and are bound to specific use > cases/implementations > e. g. MySQL resources are only for MySQL database access. Meanwhile, > callables > can be made "freely" (couldn't find a better word :-)) like integers or > booleans and also in some cases don't have an exact function signature. O= ne > such example I mention in the next paragraph. > I only said that it brings as much value as a resource type in usage context. Given a resource type constraint on function argument doesn't say anything to you as a consumer, you cannot just use that resource without knowledge of its type the only thing you could do is calling a get_resource_type(resource $resource) function. The same applies to callable, given callable like: 'strtolower', [DateTimeImmutable::class, 'createFromFormat'] or fn(int $x): $x*2; and when that came to your function with callable type constraint you also don't know how to use it without some reflection inspection cause the type doesn't bring much value. While fulfilling for eg. delegate gives you guarantee that when a callable/closure is passed it matches your expectations and you can use it right away without reflection inspections. You no longer need additional data to use the variable which applies to callable and resource as well. Speaking of a snippet you showed, I'm not sure how that implementation woul= d > work with "dynamic" callables. For example let's assume we have a framewo= rk > that allows registering routes with placeholders to controllers, like thi= s: > `$router->register('/post/{id}', [$controller, 'show']); // this would > pass a > single parameter to the callable` > `$router->register('/user/{id}/post/{id}', [$controller, 'showFromUser'])= ; > // > this would pass two parameters to the callable` > ...in this case, we can't know how many placeholders/parameters a functio= n > can > have as that depends on how many placeholders are in the string. A > framework > can only resolve these at runtime. > True. In this case, it'd be hard to create a static constraint for callable/closure check but actually this is not the case we're looking for. Things where mentioned delegate match perfectly is the places where your expectations to the callable/closure type are static and known at the time when writing code. Given that in a situation when the input and the output types are known this would bring the benefit of runtime check before use. Cheers, Micha=C5=82 Brzuchalski --00000000000082fdc305a3e49cb3--