Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115252 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43766 invoked from network); 1 Jul 2021 11:44:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Jul 2021 11:44:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F37711804F3 for ; Thu, 1 Jul 2021 05:05:04 -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 autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-vk1-f180.google.com (mail-vk1-f180.google.com [209.85.221.180]) (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, 1 Jul 2021 05:05:04 -0700 (PDT) Received: by mail-vk1-f180.google.com with SMTP id c17so1219620vke.3 for ; Thu, 01 Jul 2021 05:05:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=3D/xvCQtkPAjxQQtGOeYscX+Q88DDHNydXqIM+X0CXk=; b=B4m0q5/GPknVBnJoZ3pmM+A+o0lkVr2ntUSIJNGD3z2z6Bh6+yKTDiZ350kHlx5U57 bN1kBLU9ZsuTMa+vwsOjo1QqNYc3X71pN9D2I908PxFk8Xg9IN2zO3fvDtsFCjQESzab xktBK8Rxi9j+L9m8zYXzMq9hG2falefL9bbPCTPVY4lyB4xtlIb6y4R5lwHUfd/PnUzp r97UC6Va8unXESEnPi2vIaxdsJZvwILJ725L/Ust1BaCdjZ/qoetwBqXZYJG1L4Cjapm +r813ZLO163egrZrP8vbARRp6Znbgftt0+diFPFT3sbBOOT8RUuzP54rw9x+KAs8mYNH JJeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=3D/xvCQtkPAjxQQtGOeYscX+Q88DDHNydXqIM+X0CXk=; b=sooodZpm+b82L9xr84kEeTsCh+/AfLIDlNKVHvkdmtrclD/YFNncbny4c5cTqrhMh0 eeb8AwPrWf2B1DR/tqNJQtjhX9sxZooKpcWUHZxgEbvhE7OXlbXBugkmRDfWHau1qCoK TEPuu93xm/HossTHTrg9D0iMjLc9cPWABzogTy/yPWG3yt+Tk6CzduYcxqKRpMDqS9/p siSE9oArO4o3j3gC5zJzftAj/riLnvtzXp1vsnStKLn4CxU5o+Mu0hQfn0Gjr7n2Wvkv 73PLiQMH8Zx+wJs13je2xQiRTVaDWYHeSh3wPsbsLfrEgEiJNOq9g3s5SNrK1+WH2n4B tzXA== X-Gm-Message-State: AOAM533m/Ccu1JJdoirZpWVOXm8feILWfzMnnn/s5rXzeqgoQrvEMb8f m0s9Hx8f3yRShHAwk8Ok2NgMhw/1HCZzFoSwL+M= X-Google-Smtp-Source: ABdhPJwPKXp8TRrAqRyd2peohYTrVdYR/XhPEuBBsBd+KQRhfR0vDxnnFL0cZJfcZEOGIm7vQOUSm+dJSJDwmU3cR0g= X-Received: by 2002:a1f:9b95:: with SMTP id d143mr32901018vke.0.1625141103167; Thu, 01 Jul 2021 05:05:03 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ab0:6342:0:0:0:0:0 with HTTP; Thu, 1 Jul 2021 05:05:02 -0700 (PDT) In-Reply-To: References: <222b3921-3d9b-47f9-8d13-e6a123f36fad@www.fastmail.com> <9f0c9565-22e1-4d94-bef5-cfc44ce02dc5@www.fastmail.com> <17a5d374765.1289062a2301127.8166821672739325531@limesurvey.org> <8e6ad5a6-f627-4e3f-af04-6384ab6147f0@www.fastmail.com> Date: Thu, 1 Jul 2021 17:05:02 +0500 Message-ID: To: =?UTF-8?Q?Olle_H=C3=A4rstedt?= Cc: Larry Garfield , php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [Vote] Partial Function Application From: office.hamzaahmad@gmail.com (Hamza Ahmad) Hi all, While I was reading through the discussion, I found a question related to the conflict of constant names and functions names. In other words, `strlen` can be both a constant name and a function name. Thus, in pipe RFC, it can go confusing whether it is a constant or a function name when called this way: ``` 'abc' |> strtoupper |> md5(?, true) |> bin2hex |> base64_encode; ``` In Javascript alert and confirm are by default names. In reality, they are methods of window object. When they are assigned to a new value, they don't give a reference to the methods of window object. When a function or a method name is referred without parenthesis, JavaScript returns the function object. It is Useful because it does not require quoting. For example, `window.setTimeout(alert, 1000);`. A more popular example is `if (window.XMLHttpRequest)`. Even I tested this, and it worked. I hated this behavior. ``` function ok(){}; console.log(typeof ok); ok =3D 123; console.log(typeof ok); ``` In PHP, all in-namespace symbols are first searched in the namespace. If not found, they are looked in the global namespace. If still not found, the error is thrown. In the light of these two examples, I have these suggestions: 1. declare all function/method names respectively constants and variables by default and make them modifiable. This functionality is present in OOP; it is possible to redeclare constants and methods that are non-final. 2. As you have removed the ability to declare a case-insensitive constant, stop invocation of function names case-insensitively. Of course, it requires an RFC. 3. Disallow declaration of constants and using the names of functions static methods. Same applies to variables and non static methods of a class. As a result, no one can declare `strlen` as a constant. If one tries to make a method with a name of a property, it will also get an error. I don't know how many bc breaks these applications will bring. If they are approved, I am sure it will not only solve the problem that gave birth to this idea, but also it will prevent bad practices. For example, ``` wrote: > 2021-06-30 19:10 GMT+02:00, Larry Garfield : >> On Wed, Jun 30, 2021, at 8:59 AM, Olle H=C3=A4rstedt wrote: >> >>> > I've been pondering if a completely different approach with a prefix >>> > symbol would be able to be less complex, and the simple answer is I >>> > have absolutely no idea. But we are running low on symbols... >>> >>> Ah, I found the technical details that Joe gave me (right after I hit >>> send, of course). Quoting Joe: >>> >>> "the engine expects certain things to happen, and is designed and then >>> optimized around those assumptions ... for example, a stream of INIT, >>> SEND, DO_FCALL is not meant to be interrupted, the first fundamental >>> change you have to make is making the engine aware that stream of INIT, >>> SEND, + are not always followed by DO_FCALL " >>> >>> So yes, it sounds like hooking into the function call process is where >>> the complexity comes from. Which suggests that an approach that works >>> using a different syntax that desugars to a closure would avoid that >>> issue, but then we need a syntax that wouldn't be ambiguous, and that's >>> getting harder and harder to find. (Nikita's first-class-callables RFC >>> notes some of the issues with available symbols, and they're >>> essentially the same for partials either way.) And I've been told that >>> creating closures in the AST compiler is Hard(tm)... >>> >>> --Larry Garfield >>> >>> >>> Wrapping stuff in lambdas is otherwise the obvious solution, no? Make >>> `strlen(?)` evaluate to `fn ($x) =3D> strlen($x)`. Does it depend on th= e >>> level of look-ahead in the compiler why it's so hard? Didn't work much >>> with scripting language internals. >>> >>> Olle >> >> The tricky part is that conversion has to happen entirely at runtime, >> because we need the type information from the function being partialed, >> and >> at that point creating an actual closure is, apparently, rather hard. I= t >> cannot be done up at the AST level where it would be conceptually much >> easier. >> >> We've been discussing this for the past several days in chat, and the >> basic >> conclusion is that the PHP engine does not offer any easy way to do this= . >> It's one hard-and-messy approach or another hard-and-messy approach. So >> far >> no one has figured out a not hard-and-messy way to make it work, >> regardless >> of performance. >> >> --Larry Garfield > > Alright, alright. Guess I have to learn a bit more about the different > passes inside the compiler. :) Thanks. > > Olle > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > >