Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ncou opened this issue Oct 24, 2021 · 3 comments
Closed

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

ncou opened this issue Oct 24, 2021 · 3 comments

Comments

@ncou
Copy link

ncou commented Oct 24, 2021

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.

@dg dg closed this as completed in ea62776 Oct 25, 2021
@dg
Copy link
Member

dg commented Oct 25, 2021

{lamda} was used for functions created by create_function()

@ncou
Copy link
Author

ncou commented Oct 25, 2021

Thanks for the answer 👍

@dg
Copy link
Member

dg commented Oct 26, 2021

Thanks for report :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants