Skip to content

Instantly share code, notes, and snippets.

@jhartikainen
Created February 16, 2011 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhartikainen/829408 to your computer and use it in GitHub Desktop.
Save jhartikainen/829408 to your computer and use it in GitHub Desktop.
Using $this in closure example
public function x() {
$self = $this;
$closure = function() use ($self) {
//You can call public members of $self here but not protected/private
}
}
@wiselancer
Copy link

For what purpose you need this?

@jhartikainen
Copy link
Author

For PHPUnit's returnCallback, to check values on the object passed as a parameter to a mocked method. Used to do that with just a normal callback but this is more convenient :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment