Closures in Routes3:38 with Jonathan Barrios
Closures are anonymous functions that don’t belong to any class or object. Closures don’t have specified names and can also access variables outside of scope without using any global variables. Closures require less code and are simpler to write, which makes them handy tools when creating simple functions, like the About response we created in the last section. You'll use closures frequently when creating routes, so what is a Closure, exactly? PHP code can execute inside of Closures, much like functions do-- for example, you can work with variables and perform math operations within a closure that’s defined within a route. That’s a mouthful, but it’s simple-- routes can execute code using Closures, which are simply anonymous functions.
You need to sign up for Treehouse in order to download course files.Sign up