Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115196 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40191 invoked from network); 28 Jun 2021 21:46:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Jun 2021 21:46:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7EECE1804F3 for ; Mon, 28 Jun 2021 15:06:08 -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,NICE_REPLY_A, 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-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 ; Mon, 28 Jun 2021 15:06:08 -0700 (PDT) Received: by mail-wr1-f43.google.com with SMTP id u6so984849wrs.5 for ; Mon, 28 Jun 2021 15:06:07 -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=OPNj5iTsVbfORxID1i1sNPp1bwSblUozIcHwSrw9McY=; b=KLN/31pQToydk4hjH2cJ+mymIUrAirh485q4nW4dDqot8j4qg0ra+x9Fuk1+DtEbMx ZvpXR0Mse0tZvtCBhOdhXtIbDNBlDvjr2oz6BtwFRQVIUhKjexGx9RvPvslEBbxWgb37 5B2cmxd/4djCGaxEmmKFfAkLXQrGX65sQYmNTQDXKUJr/E55hr+Yq3RwX8fizT79Q58h +2xkd7T011KQTwUntO+LxVP5Fjfo3T9b9ZR5dinAFv+FE01rZUg8IRCiZya6uWSodKCM 725hrOLyoC3kl4ppOjwmLAfuvyWArzvy0mHFzlBxaY+1mTj2cvk1grVLAJfdYpUqCiZQ HUUg== 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=OPNj5iTsVbfORxID1i1sNPp1bwSblUozIcHwSrw9McY=; b=oFhLJ63URxniPoCLtSPd8VRJP66fA7CuSRFIxUEVA0Nhps07ndh0HimqHWGIIdk7Iu QC6MPMRotiCa6qA0l9otzUL1tjsdhNo5gAs9PLVQJRgKqp4gkOzTPuLQdia/rPD0BSCb aiI1OsF2PpH5vNTPmgsOsWBbJbVuyEPstI6j3TeOXWRjCMf1rB7QEldoxKhEyO7JS3Lq E3bv12aJ+GpzRJPip1oaNegxwB1y/+8Wa88iZscx4hQRbLRqSFT+4kXZN7cEntfArns+ ObLKffXq1uBJA7j103SUcU6xrDfF5GXuQh6ZOyAYkjr5tNwscmB03c+p9jHoouBWPv8e EYkQ== X-Gm-Message-State: AOAM530bzvIJhaQ3o40s35VMkkMyntSH6XiuW43lYb5cVujc3+IKFUNt 9N4Fw5ekpTGDTv7gitG47Jyg9MXvrB4= X-Google-Smtp-Source: ABdhPJxRfzmtZeeVujintdupjJoI4kzcIeLk3UJOqxIwqDp4hDOkzV8DT6QCrXlV9IKk7bdv6oAYBg== X-Received: by 2002:a05:6000:154f:: with SMTP id 15mr21478468wry.208.1624917965991; Mon, 28 Jun 2021 15:06:05 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id c12sm715158wmr.27.2021.06.28.15.06.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Jun 2021 15:06:05 -0700 (PDT) To: internals@lists.php.net References: Message-ID: Date: Mon, 28 Jun 2021 23:06:03 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.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] [RFC] Pipe Operator, take 2 From: rowan.collins@gmail.com (Rowan Tommins) On 28/06/2021 21:28, Olle Härstedt wrote: > Sorry for hijacking the thread, but are there no other alternatives, > really? Just brainstorming: > > 1) Setting to silence the warning. Just to reiterate: in PHP 8.0, an undefined constant is not a warning, it's an error. My apologies to code golfers: you can no longer save two bytes by leaving the quote marks off your strings. However, that's not really the problem. The problem is when there *is* a constant with that name: const foo='strtoupper'; function foo($x) { return 'test'; } $input = ['hello', 'world']; var_dump( array_map(foo, $input) ); // this runs strtoupper(), not foo() This doesn't work even in old versions of PHP where undefined constants fell back to strings. Even in cases where this trick did work in older versions of PHP, it was just a variant of option one, "use our current ugly callable syntax" - it saved you those two bytes, but it didn't actually provide you a function reference. Unifying the constant and function name tables would not be to just a different way of writing strings, it would let array_map(foo, $input) actually check that function foo existed, and represent callables as a proper type. Meanwhile, to let array_map($object->foo, $input) do the same thing (instead of the current [$object, 'foo'] syntax) you also need to unify the method and property tables, which is probably even harder. > 2) Setting to silence the warning IF and only if argument expects a > callable, like in array_map (won't work with a pipe() function, > though, since pipe() would take any number of arguments and that can't > be typed) In the general case, this is a non-starter: the parameters need to be parsed from the source code before function definitions are even known. You could special-case a handful of built-in functions, but that would be extremely clunky. > 3) Silence the warning if you type-case explicitly, like in > `pipe($start, (callable) htmlentities);`. Another alternative is > `(fn)` as a type-cast. Not much better than `pipe($start, > htmlentities(?))`, I guess. Just different style. This falls into my third option: "add a dedicated callable syntax". That could be something that looks a bit like PFA but isn't, like Nikita's RFC; or something that looks a bit like a type cast; or any number of other ideas which have been brainstormed for about as long as I've been programming PHP. > 4) Silence the warning ONLY when it's the right-hand argument to pipe > operator, like `$start |> str_len`. Re-wording this as "interpret the unquoted word as a function reference rather than a constant when...", this one is at least plausible. In practice, though, a lot of functions don't take only one parameter, so the previous pipe proposal included a placeholder for which argument you wanted to "pipe into". At which point you don't need to special case keywords, because you can just write this: $start |> str_len($$) Regards, -- Rowan Tommins [IMSoP]