Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88667 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87099 invoked from network); 4 Oct 2015 15:36:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Oct 2015 15:36:46 -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:34948] helo=mail-yk0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4F/98-31315-D8741165 for ; Sun, 04 Oct 2015 11:36:46 -0400 Received: by ykdz138 with SMTP id z138so150574431ykd.2 for ; Sun, 04 Oct 2015 08:36:43 -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 :content-transfer-encoding; bh=K//rCdcuYK1heU4VA7eKUXbStGUMK3h1y8EaAuzzqnw=; b=I3bKAtgvDxzmDsol64GcWpSTq5UjApzVZ30ytoWeIzON8OX4mvbTGUzyPuLCHyafbH MOyFt4MJ6SlqJ/T8V0VyNKDAePmTJqOA5CiZ72Wa6fqEv9pO/thYrSFOVoziKPRSwagu HiQDFKx4DUgen3e5MZZ6ZAD6pa+NTlQj+mr3qRUGAvikvnvYfsSgptv7sRpSJQgTpLig +a4fXDTlSFqdriXE0XzStyzu664EEnbUbylYJvILMXGRtERu71AcFjJ60R2ozAVOKioS mVXbFdFWEH5YAOLG1RhkPnbWlJqDPoudJUmfF3NX8vdPaW6vZ6NHIZUQP2qUs56U7tPU xiow== X-Gm-Message-State: ALoCoQlQIjhrplrxb+1hCMpCIFFE5V7lDgLWgr2hPWqgLL4iAcohRuPlRO6hvvKxj3BCAH6GBYZ6 MIME-Version: 1.0 X-Received: by 10.170.121.142 with SMTP id n136mr21463821ykb.116.1443973002994; Sun, 04 Oct 2015 08:36:42 -0700 (PDT) Received: by 10.37.76.137 with HTTP; Sun, 4 Oct 2015 08:36:42 -0700 (PDT) X-Originating-IP: [2.96.92.51] In-Reply-To: References: Date: Sun, 4 Oct 2015 15:36:42 +0000 Message-ID: To: =?UTF-8?Q?Pavel_Kou=C5=99il?= Cc: Marco Pivetta , PHP Internals List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [DISCUSSION]: Closure from callable From: danack@basereality.com (Dan Ackroyd) Hi Pavel, On 4 October 2015 at 11:31, Pavel Kou=C5=99il wrote: > > and what about changing the empty ctor of Closure to > __construct(callable $callable)? > > And the usage would be new Closure([$this, 'abc']);? > I'm going to change the RFC to use the 'named constructor' Closure::fromCallable which should address the naming concerns. IMO, default constructors are bad and I encourage people to stop using them. In this case they are bad as they can't be passed as a callable. Either 'closure' or 'Closure::fromCallable can be passed as a callable: function createClosure($callable, $name) { // do stuff return $callable($name); } foo('closure', 'bar'); foo([Closure::class, 'fromCallable'], 'bar'); foo('librarySpecificClosureGenerator', 'bar'); In addition, it's inappropriate to use default constructors in a class where it is even slightly likely that you are going to have more than one way of constructing that object, as you then have to hack around the fact that you want to create other named constructors that don't call the default constructor. cheers Dan