Skip to content

Callback - bug with closure and private/protected methods #270

Closed
@ncou

Description

@ncou

Hi,

Nice piece of code. There is a bug in the Callback::unwrap function (https://github.com/nette/utils/blob/master/src/Utils/Callback.php#L127), the return value could be an array and not a callable in case you have a closure using a private method. for exemple :

class MyClass
{
  private function myPrivateMethod() {}

  public getCallable(): callable
  { 
    return \Closure::fromCallable[$this, 'myPrivateMethod']
  }
}

Callback::unwrap((new MyClass())->getCallable()); // This will raise a TypeError

I think the return typehint for the unwrap function to be 'array|callable' instead of simply 'callable'.

And by the way i have see in the toString funtion a case for "lambda" when does this "if" is used ?

Have a good day.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions