Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103390 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14521 invoked from network); 26 Oct 2018 16:14:21 -0000 Received: from unknown (HELO mail-vs1-f54.google.com) (209.85.217.54) by pb1.pair.com with SMTP; 26 Oct 2018 16:14:21 -0000 Received: by mail-vs1-f54.google.com with SMTP id c205so587264vsd.3 for ; Fri, 26 Oct 2018 05:29:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=OTP31E99z1lRgPVGYTeu0iosMPmD162Pbr+4kuoa2mQ=; b=XcsNlcNO1+nFyQWPUxvrFy/L9XiTsQPNgql/1IMGeai8WZA+Uvk9PKdrAK+lsMPENh QJ2yt0PQ7biXI3Nzp3KUt5N0KWXGXbbQgO6XdZ2fOXw0Et1LSQsiVn8Mkzo+Ith1RJjK LzEIz90OuZXTObXT6LoFjgYsVTToIwAJwEXfYsIN8uLahEQpidB7yrb4p4yjsEXIwEil HDwa9mfeN9zQt2CEfBMLUFmJ2yF8pVKwp2Gn/ZZjxf0AVeh050RKEYns2fzKjOgNJGkz l5tvz/LGH+6eRoitQqzqkg6Yo+N5FazWtIJuFgsQk//JmOgkFz1fbOuLUlSWoXpHUuDQ A2iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=OTP31E99z1lRgPVGYTeu0iosMPmD162Pbr+4kuoa2mQ=; b=kb+F2EmmyHSgK4GuGMXSxxcCBcPeQ6+80Eq/8GWK6xUEaeN/YLbmKHeoMdfyBICEGG GLFOExK9JIRHtT1CXAx+J1rDDdxQ6pxY489huvA4QcAO4m4LjSjBx2t8WWNjZP0cS7Oi buOi+R4pVDb3rU0JqLgpAuUBiY7H+i3lreQmIZArFSSgr7oOCbDRxwZpiFukBuCBczu8 BYEl5gWdYcaaiBcX35hTM4GW/sRvXcUBvyOd2W+ZL+KR+/ZbRTuqv7B3GGFQsGmIYLp6 hblkpniGZpLzilVvGPvI4n47nBk24EgY0tzZ+y7jhMI74UowINWjGrudAb5iF3AcMyNB +HTg== X-Gm-Message-State: AGRZ1gKyNEylsLmoZPyn285Lh7hsfJtD7kTlfA5IehPldi0L5g+kkTsF kAch6a0nre3GdRTevaU7HJpSGYZZu6xhco2CJB0tpRHT X-Google-Smtp-Source: AJdET5e0ODXnB1UrMKGU+QnQvu2TTgSnwG1dRghMyzYyvBBYetGSRr69W5/EYygcFO5YBPwrnBDM9pQ0VguYhOrHp7E= X-Received: by 2002:a67:2544:: with SMTP id l65mr1417650vsl.225.1540556997692; Fri, 26 Oct 2018 05:29:57 -0700 (PDT) MIME-Version: 1.0 Date: Fri, 26 Oct 2018 14:29:46 +0200 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="0000000000009a948b057920e0cf" Subject: Idea for better function callbacks (another syntactic sugar) From: crocodile2u@gmail.com (Crocodile) --0000000000009a948b057920e0cf Content-Type: text/plain; charset="UTF-8" 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 -- Best regards, Victor Bolshov --0000000000009a948b057920e0cf--