Categories
PHP / MySQL

PHP 7 – Closure

Another cool new future in PHP 7 allows to bind a closure to a specific object on run-time with the addition of Closure->call() function.

This method takes the object as it’s first argument, followed by any arguments to pass into the closure.

Syntax

Example with PHP7:

Before PHP7 we use to do something similar to below example with bindTo() method and which allow creating new closures that have $this bound to a specific method. However, it has not been possible to bind at call time and you must instead create a temporary new closure.

By Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.

Leave a Reply

Your email address will not be published. Required fields are marked *