Hi Pavel,

On 4 October 2015 at 11:31, Pavel Kouřil <pajou...@gmail.com> 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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to