News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Andrew Podner:
Closures, Lambdas, and Anonymous Functions
February 21, 2013 @ 13:02:13

Andrew Podner has posted an introduction to a concept in PHP that may not be easy to immediately grasp for someone relatively new to the language - the idea of lambdas and closures.

Beginning with PHP 5.3, the anonymous function, became available to developers as a means of improving flexibility and increasing the number of tools at our fingertips to build powerful PHP applications. What I have been seeing a lot of as I read through documentation is more frequent use of terms like lambda, closure, or anonymous function, and sometime the terms are often used interchangeably, so let's take a deeper look into what all of these things are and what differences, if any, there are between them.

The post looks at lambdas first, defining them as "functions without names" that can be assigned to objects or called inline when needed. Next is closures, and it's noted that, in PHP, there's really not much difference. They both also allow for use of the "use" statement to import values into the function's local scope. He mentions the "$this" update that came in PHP 5.4 and includes some arguments against their use too.

0 comments voice your opinion now!
closure lambda anonymous function introduction


blog comments powered by Disqus

Similar Posts

Tiger Heron Blog: First steps with PHP - booting a script, Part 2

Oracle Coherence Blog: Getting Started With The Coherence Memcached Adaptor (and PHP)

MaltBlue.com: Zend Framework 2 ServiceManager - Web Application Development Simplified

NetTuts.com: Travis-CI: What, Why, How

DevShed: PHP Closures as View Helpers: Lazy-Loading File Data


Community Events





Don't see your event here?
Let us know!


introduction podcast release community install list update laravel package tips symfony opinion deployment language zendserver framework api series library interview

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework