Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103401 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4821 invoked from network); 26 Oct 2018 23:50:51 -0000 Received: from unknown (HELO mail-vk1-f181.google.com) (209.85.221.181) by pb1.pair.com with SMTP; 26 Oct 2018 23:50:51 -0000 Received: by mail-vk1-f181.google.com with SMTP id 22so592311vkz.11 for ; Fri, 26 Oct 2018 13:06:33 -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=M/tHjQq2qq1dbhcZWnnb4hdFczVFR7/DRHuWW+zL8xs=; b=cQ1dK4SOTrozWGJUPQrxxhRe1z9Z5fbPQVWrosv9s29IOUq9RITTQ7QVnp/drhuXh+ RF44vi+16v2J8JwUixRLV2tmgcuGaw266arUjN6MBgJz7R3fvP42BdhJ4SHN5XfO/plx DzymsYOKI8/6fWk7hqHnegBYcMDpIJ26/ZcahkR7kWAxfor7LHR8RnGDC2IWF8tXpTC0 UOziB+5TeG5mV38ss4B1YbiemJ824jMUDspLYH8ztIXWtwtBv06zmpNaXKksfkz5lOmk jA+mItaMmMD2YyvPZWcQ8XI5aLlh7672Ykl3hbYjinEiW7wQfWXSnPeAWEpqLD7wNUj5 PsZw== 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=M/tHjQq2qq1dbhcZWnnb4hdFczVFR7/DRHuWW+zL8xs=; b=H5rzx5+3Fx2eRtg0ddaRE7MSbowaUzth1UyFsTb27XHHdZQBXUi2bZUVjIkHwWoZAY No/aNoeRL6NLhR806Y9BL1+t+KBxnme79NuC8xN5r04+GpEMOI6qwGE5oyBXdkAojUjQ kAQ6einwrC9nWTcd+UddsOW579aIfMXx+egV1Wj22n99wB3AcqA/5U8ZIhMRtv8F6XDj TSUVSJV41IrpPYxgEFpmufMrZ+whG5A3Ga8s+sZEJ0DNSsWzvacLQ0pdtw1yt3yHynC7 aWK2Tm8PenEa4tsDI/xxb9nkdv12OEXCjNw3IH2ylkuN8OPsU0o2X+hOR1ffB3z022Sw nHkg== X-Gm-Message-State: AGRZ1gLjxSZAN7fSLpUpVf0DLRGkvFlzr7urVhjfji5cYcvyggPfs5qB iQ3wNolOcKbr8Qg6DFb3n1Z91uE+47ZLLyvSRCk= X-Google-Smtp-Source: AJdET5d4Xnd0uIaIwHHwYFQyZNbT6RhcusKj83WU2qH/KmK0trS00NXCM09f548UwtxG5J+8VnWUatwoTmk8TOZX/kI= X-Received: by 2002:a1f:8011:: with SMTP id b17mr2211419vkd.31.1540584392990; Fri, 26 Oct 2018 13:06:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 26 Oct 2018 22:06:20 +0200 Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: multipart/alternative; boundary="0000000000007da4b705792741f1" Subject: Re: [PHP-DEV] Idea for better function callbacks (another syntactic sugar) From: crocodile2u@gmail.com (Crocodile) --0000000000007da4b705792741f1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sorry for a bunch of replies that simply have lost a lot of context.. I'll try to summarize it all here: > I believe the proposal for short lambas (which should get resurrected at some > point) would handle this case well enough as well as help a dozen other > things. To wit: > > array_filter($names, |$x| =3D=3D> trim($x)) > > --Larry Garfield I don't think it's quite the same, and although I can agree that short lambdas look better then normal in this context, I would still prefer function::trim > In my opinion "ideal" here is that our symbol tables are merged, so > referring to "trim" in any context will resolve to at most one symbol That sounds like a plan, and if there is a reasonable support for that, then we could just have array_filter($arr, trim) - then its way better than my proposal, and should also work with class methods. > Right click on `function::trim` - Find Usages. Basically allows to find all > usages of a given function, including the callback usage. Yeah, that was part of the idea, the other being to make these callbacks semantically different from strings. Its just weird that a string is callable, isn't it? > And about methods? How it should works if I wants to call a method from a > custom class? It should be function::CustomClass::someMethod? My proposal would not work for methods. function::CustomClass::someMethod - that doesn't look great at all, at least to me. On Fri, Oct 26, 2018 at 10:01 PM Crocodile wrote: > My proposal would not work for methods. function::CustomClass::someMethod > - that doesn't look great at all, at least to me. > > > On Fri, Oct 26, 2018 at 6:08 PM David Rodrigues > wrote: > >> Em sex, 26 de out de 2018 =C3=A0s 09:30, Crocodile >> escreveu: >> >> > Hi internals! >> > >> > I have this idea of improving the way to specify callbacks for good ol= d >> PHP >> > functions. For instance, I have this piece of code: >> > >> > --------------- >> > array_filter($names, 'trim') >> > --------------- >> > >> > The callback function name is specified as a string, which makes it >> > not-so-obvious, although this is definitely a PHP way. An alternative >> would >> > be to rewrite this using a lambda: >> > >> > --------------- >> > array_filter($names, function($name) { return trim($name); }) >> > --------------- >> > >> > This is way more wordy, and I bet most of us will go for the first >> option. >> > >> > What if we had a more clear way of specifying those callbacks? I sugge= st >> > the following: >> > >> > --------------- >> > array_filter($names, function::trim) >> > --------------- >> > >> >> And about methods? How it should works if I wants to call a method from = a >> custom class? It should be function::CustomClass::someMethod? >> >> >> >> > >> > It is, I believe, more clear then a simple string, just a bit more >> wordy, >> > and since "function" is a reserved word which never had anything to do >> with >> > "::", the lexer/parser could probably find a way to deal with this kin= d >> of >> > syntax (well, honestly, this part is totally unclear for me because I >> only >> > work with PHP from userland). >> > >> > Does anyone else find this could be a good addition? Or is it not wort= h >> > considering? Or maybe I am missing some obvious pitfalls? >> > >> > Cheers, >> > Victor >> > -- >> > Best regards, >> > Victor Bolshov >> > >> >> >> -- >> David Rodrigues >> > -- > Best regards, > Victor Bolshov > --=20 Best regards, Victor Bolshov --0000000000007da4b705792741f1--