Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88666 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85073 invoked from network); 4 Oct 2015 15:20:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Oct 2015 15:20:28 -0000 Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.160.177 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.160.177 mail-yk0-f177.google.com Received: from [209.85.160.177] ([209.85.160.177:34767] helo=mail-yk0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B5/48-31315-BB341165 for ; Sun, 04 Oct 2015 11:20:28 -0400 Received: by ykdg206 with SMTP id g206so149143141ykd.1 for ; Sun, 04 Oct 2015 08:20:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=nPP5Ki1ETNgN68Qfu59ahPi3RWMcsV4uGQatqcRrrv8=; b=Yq0NXIgBNhEeHou2nN9vydhxaFiNmUNsdtw07fCXuitiVJIRZyI2J+PZdn1sdRqlW6 OIEJh0fSbLK08lWDYaxl7gBYn5AYcEb6ASVB3RtIse86GmrhfYmA+mlS5U/17t+7XvuV vmYoveYylR/yD44z9RvCyZQbQ56psTsGwDxtHC0FTMvLPseE6L9DZY+6DxiKaG8Ndiyz JjHup7sc5Alub6Cy1KXfWOOuVZEbE+wKEIuXhwhDEJv2rI1Bx8P5gyVizAA5R6RUhj6k Dq1blmAgAOA8npqCOErv3TGl5Dqq/njni74qjrZnHavSEBNJnsiVdZOOVXph8x48fJGb 0OcA== X-Gm-Message-State: ALoCoQkkzz88PTLmrk2umakddil7ZrFHdXtOXNNqk8YyHFnnnZszNWIwDKAQ8IVco8ZDh1rBO981 MIME-Version: 1.0 X-Received: by 10.13.229.68 with SMTP id o65mr21089348ywe.62.1443972025102; Sun, 04 Oct 2015 08:20:25 -0700 (PDT) Received: by 10.37.76.137 with HTTP; Sun, 4 Oct 2015 08:20:25 -0700 (PDT) X-Originating-IP: [2.96.92.51] In-Reply-To: <5610FC92.4090005@dasprids.de> References: <5610FC92.4090005@dasprids.de> Date: Sun, 4 Oct 2015 15:20:25 +0000 Message-ID: To: "Ben Scholzen 'DASPRiD'" Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] [DISCUSSION]: Closure from callable From: danack@basereality.com (Dan Ackroyd) On 4 October 2015 at 10:16, Ben Scholzen 'DASPRiD' wrote: > > you could just do this: > > return function ($data) { return $this->genericValidation($data); } > > you could just do this: > > return function ($data) { return $this->genericValidation($data); } Yes, there are workarounds possible that don't need anything new i.e. either implementing the closure generation function in userland or doing a programmer generated closure. The downside to writing the closure by hand is more obvious when the parameters and return value is typed: class Validator { private function genericValidation(callable $foo, string bar, UserData $userData) : string {...} public function getValidatorCallback($validationType) { //... return function (callable $foo, string bar, UserData $userData) : string { return $this->genericValidation($data); }; } } All of the type checking has to be repeated in the programmer generated closure, which is annoying as it means you have to keep code in different places synchronized. Additionally PHP is kindof slow in function calling. Wrapping the method to be called in a userland land function makes calling it be much slower than using an internally generated closure. In addition to the function call overhead, all of the paramters and return type will have their type checked twice; once when they're pased to the closure and once when they're passed to the method. cheers Dan