$that = $this;
$closure = function (...) use ($that) { ... };
Found on: http://css.dzone.com/polls/what-new-feature-php-54
Could someone please explain what it does? Preferably with an example.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
that is a way to have access to the methods of a class from a anonymous function defined in it. but since the title is “php 5.4 closures” you don’t need to do that any more, this is one of the updates made in 5.4, you can use $this (without passing it to another variable like $that). you can see here http://php.net/ChangeLog-5.php that one of the changes is “Added closure $this support back”