Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free triallihaoquan
12,045 PointsCallbacks in PHP?
In the video, he talked about callback functions and anonymous functions, but I don't understand how callback functions and anonymous functions work, when to use them, and why?
1 Answer
Joe Cochran
18,249 PointsAnonymous functions are unnamed functions. They are often used in situations where you would like to pass a function to something.
Hampton discusses closures in the PHP Functions course Stage 2 - PHP Closures. It may also help to check out the PHP.net documentation on Anonymous Functions for the official definition and some examples of their use.
lihaoquan
12,045 PointsThank you, I'll definitely check them out!
Lestaf Santiago Pereira Pimentel
133 PointsLestaf Santiago Pereira Pimentel
133 PointsSorry for the late reply, but the previous answer only touched on Anonymous functions. Callback functions are functions that are called at the end of another function, one of their most obvious uses i can think of are in an express server with javascript, where there are functions that accepts another function as one of its arguments, say you want to format a GET request, so you define a function that does so and use it as a parameter in Express's GET function.