Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103397 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98095 invoked from network); 26 Oct 2018 23:40:41 -0000 Received: from unknown (HELO mail-ua1-f51.google.com) (209.85.222.51) by pb1.pair.com with SMTP; 26 Oct 2018 23:40:41 -0000 Received: by mail-ua1-f51.google.com with SMTP id e16so813035uam.1 for ; Fri, 26 Oct 2018 12:56:23 -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=BH04fQqZI5YjqHGxMXVHYI6WTQKNCZxIubsFtBIcDhU=; b=ohM+UA4BW1X1CBpNsfl7CfE5P0suoNHJCnrXLnvKJYF+DoUqYY2ZAsJH8OknBmCXaH TafQzPCm984NAQowu+vjdEXW2zsG6ARUfzjLkJI/UY8P2kMIFc9VfoTwP6bvz/JsPLut TA2Ms2uqVTNQzqRYKMZmQCTtTpDc9+Gxam5ZkiAg7HAu9XyOMVv3Z1L5CN7uCJ45SOH6 qsYzY5Ob4TVQG/y9qPbhjXObB/3NLNhsPqZZC+WSr2lGY8UONxSpg9j3C4Qo/ALK9YSz CmTzijRYR9Bq5JbxgdjcWlAE3uTrYQpG0kuDUvexztywgWsvEHdk5FnxyaKH0IEOAhZI J+/A== 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=BH04fQqZI5YjqHGxMXVHYI6WTQKNCZxIubsFtBIcDhU=; b=nYAGwhZdfwETCin4FPInTk+nojjhZHNHGU5xjY967rzwnxV6tYNtTyF39+o+qOe5Fh DXfTacXtpb2NxHvu2IJ7vADdRutH/CrZnH5fR73tU+MJc6+Wr210V3M+TRVU917jZ5Zr 3VzSo2SYw7am/Is8U+zhptEcMOgiyNaC1UFe2SI5cf3EwT3zMM+3vf0tPFDGh/eQdD1o 01VTlKrZncSxYpCto6BWGiP47UZ/l7RDM9V54x/g1hWCH2DX3iEzvjASBvVi9fiyJA6U YRbMtcbxFpWzXAC//ciN1mRQJ6lgm4nMD5Lw1vtMagAbKe7d3p6jG/rfcSC/h7looj13 knlw== X-Gm-Message-State: AGRZ1gLGZYjYAOMXjUoWoBQB5cTaeg07dVzjruE0AFP8HQHkHYjB4CWb ol9ubhS8Vu/ECneYBtIg4BRC27M593IeOy1wWhkZn3lh X-Google-Smtp-Source: AJdET5fSjuTYB3gtp/hJwmL0z+ithOjBkDI+qp6EYJ2RFHWJfNpg2m0YpYvPLNNJljwhc36MTchTZ2Ev2cUG6KRpVgQ= X-Received: by 2002:ab0:7034:: with SMTP id u20mr2147371ual.4.1540583783454; Fri, 26 Oct 2018 12:56:23 -0700 (PDT) MIME-Version: 1.0 References: <2370262.6EcsR2toYx@vulcan> In-Reply-To: <2370262.6EcsR2toYx@vulcan> Date: Fri, 26 Oct 2018 21:56:10 +0200 Message-ID: To: Larry Garfield Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000028dbd80579271d5e" Subject: Re: [PHP-DEV] Idea for better function callbacks (another syntactic sugar) From: crocodile2u@gmail.com (Crocodile) --00000000000028dbd80579271d5e Content-Type: text/plain; charset="UTF-8" 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 On Fri, Oct 26, 2018 at 5:42 PM Larry Garfield wrote: > On Friday, October 26, 2018 7:29:46 AM CDT Crocodile wrote: > > Hi internals! > > > > I have this idea of improving the way to specify callbacks for good old > 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 suggest > > the following: > > > > --------------- > > array_filter($names, function::trim) > > --------------- > > > > 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 kind > 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 worth > > considering? Or maybe I am missing some obvious pitfalls? > > > > Cheers, > > Victor > > 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| ==> trim($x)) > > --Larry Garfield -- Best regards, Victor Bolshov --00000000000028dbd80579271d5e--