Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108559 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72852 invoked from network); 14 Feb 2020 08:50:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Feb 2020 08:50:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 60E431804AB for ; Thu, 13 Feb 2020 23:05:04 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.6 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_H2,SPF_HELO_NONE,SPF_PASS, SUBJ_ALL_CAPS 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-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.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 ; Thu, 13 Feb 2020 23:05:03 -0800 (PST) Received: by mail-lf1-f65.google.com with SMTP id m30so6035108lfp.8 for ; Thu, 13 Feb 2020 23:05:02 -0800 (PST) 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=Ndy+UxP0r9RuKHLHXHW80pwpGy7g3/rCEBHUZJ6Jlu8=; b=if+p0iGXctFUhmQzAcCzd+r+Oz6qZ3fshbkRcPrfLgCBSyVo13EP02yO7O4a7UILYA MSki3AiyQON0AbU0u20MtG8slWBN3fT1bDjRO9fJk2Ze2YdqWS5GnVvAIHdS32actKCR KATqG2bA/1OjdmtBdbMI6YbgZvVOYaECPY0PQnTmbANd3/x/xd37Rb62HQJxXoEA+Vs9 QYt0FSt9gpyJtKfJUn4zO+6C7POZJMJ6fj4TckWHRxZvlUTrDPsAiPFNsCwS2QsuIcO3 86OXD0YYrXNDNp3tAIGZrNhMpJtp8PiOWDbr3/paBdXaroSFB/VdA0BWmktwqc2LmHlR ZA1w== 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=Ndy+UxP0r9RuKHLHXHW80pwpGy7g3/rCEBHUZJ6Jlu8=; b=K4EzHbowL0qinRcijtIRw91+LjX8YyBv7HWBFOK3cPk6dx2DGMPQcpi/bBJizW8OP0 rpK3Y/WfU9411d9xZ0Xbf8GsKJEB4J5SbaheUtnVDa23dLiwqjVejKh6OV/JjMPhLcGr 5sLRPBDEokf1yKEw+r00sMUl3DeP5qMTtcvVb5Ms4HiiQRQxqiUUoXP+uwsWRq6z7cFY n3AMJsqOmyrg21vO5TwSzuCxpwZR5tiGGLEpML2sh9BeHMTbQ9/lI7BC6lF03i8zwN/o VCwLKAnJseuMZdLKI4tU3rSXPdRRz9NUFGUiB6S/LRuSSFcApuPoz7Wup0rb9pvTQWLH f1tg== X-Gm-Message-State: APjAAAU3nlmbVX+dfqbSTsUQFYX7rItdQaTLJjp9k47WVqKPo0HBb/an RNSOpjrqLB13RmGNSGY5QIf8vw3E+dhfFjk/jvw= X-Google-Smtp-Source: APXvYqz3SbIMzDZPjRvFMsTv1XVgvHIAsjxSdVskw5vqBJJpwMzeK8K9/RVx0ByfCmX3rYBdUJO/10yZb4d7jhKCtkQ= X-Received: by 2002:ac2:5e72:: with SMTP id a18mr937592lfr.9.1581663899636; Thu, 13 Feb 2020 23:04:59 -0800 (PST) MIME-Version: 1.0 References: <10FCCCED-B8AE-4394-91B3-0FEB448E2398@gmail.com> <2C404984-AD76-4CDF-8E1A-04DF8EF024DD@newclarity.net> <0BE8FC1E-A9BF-4A2A-9CA5-59BEE1245632@gmail.com> <938FDD44-1F60-4FE1-B0F1-E70284F5F2D2@newclarity.net> In-Reply-To: <938FDD44-1F60-4FE1-B0F1-E70284F5F2D2@newclarity.net> Date: Fri, 14 Feb 2020 08:04:48 +0100 Message-ID: To: Mike Schinkel Cc: Rowan Tommins , PHP internals Content-Type: multipart/alternative; boundary="000000000000e458bc059e83d218" Subject: Re: [PHP-DEV] [RFC] From: manuelcanga@gmail.com (Manuel Canga) --000000000000e458bc059e83d218 Content-Type: text/plain; charset="UTF-8" On Fri, 14 Feb 2020 at 01:39, Mike Schinkel wrote: > > On Feb 13, 2020, at 7:24 PM, Rowan Tommins > wrote: > > > > An idea I had earlier which might solve some of them is if what was > returned was not a normal Closure instance, but a new class like > FunctionReference. It could then "remember" the name of the function > wrapped, and implement __toString, Serializable, etc. It could inherit from > Closure, so instanceof checks would work, and bindTo would return a normal > Closure. I'm sure there's downsides I haven't thought of yet, but I thought > I'd throw the idea into the mix. > > I thought about that too, and mentioned it yesterday in a reply[1] to you > on this list. > > Here is the link to the Gist with the hypothetical code using such a > concept: > > - https://gist.github.com/mikeschinkel/78684d708358e1d101e319c7a2fdef9c > > -Mike > > > [1] https://www.mail-archive.com/internals@lists.php.net/msg100719.html > > Maybe, bettern fn: * fn(callable $to_clsoure ): *closure ? I know fn is used in arrow functions. However, for that same reason fn is the most convenient. Using dik examples( by the way, they are brilliant ): $result = Stats::of($string) ->analyze(fn(normalizeNewlines)) ->analyze(fn(readingLevel)) ->analyze(fn(countStats)) ->analyze(fn($synonymSuggester, 'analyze')) ->analyze(fn(WordCouter::class, 'analyze')) ->analyze(fn($s) => wordDistribution($s, 3)) Returning to ::function again and with a modified example of dik( again ): Now is: result = Stats::of($string) ->analyze('\Stats\Analyzer\normalizeNewlines') ->analyze('\Stats\Readings\readingLevel') ->analyze('\Stats\Parser\countStats') ->analyze(fn($s) => \Stats\Analyzer\wordDistribution($s, 3)); Could be: use function Stats\Analyzer\normalizeNewlines; use function \Stats\Readings\readingLevel; use function \Stats\Parser\countStats; result = Stats::of($string) ->analyze(normalizeNewlines::function) ->analyze(readingLevel::function) ->analyze(countStats::function ) ->analyze(fn($s) => \Stats\Analyzer\wordDistribution($s, 3)); Maybe '::function' is something long, however it wiil be autocompleted by editors and, moreover, nowadays function is a reserved keyword. Could we use "normalizeNewlines::name", but in this case: normalizeNewlines is function or class ?, because in this case could be "normalizeNewlines" a class and "name" a constant of class. Rowan put me in an awkward situation with [MyClass::class, method::function ] however, in this case, could be simply MyClass::class, 'method' ]. Because method don't need be used with namespace. ::function could be documented with advice of being used with name of functions. Because ::function is also useful in array: $filters = [ normalizeNewlines::function, readingLevel::function, countStats::function ] $content = Stats::of($string); foreach($filters as $filter) $filter($content); Regards --000000000000e458bc059e83d218--