News Feed
Sections




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

Jeremy Cook's Blog:
Recursive Closures in PHP 5.3
August 13, 2010 @ 13:07:59

In this recent post from Jeremy Cook he take a look at an interesting use of closures in PHP - using them recursively to strip slashes off a string.

One thing all of my projects have in them is code to remove the quotes added so I can handle appropriate escaping myself. This [example from the PHP manual] works perfectly but it does end up creating a function in the global namespace which is only called once. A perfect job for a closure.

He includes an example of how to do it with a normal, globally-defined function and how to handle it with a closure (that calls itself via an array_map) - a closure contained inside of itself with the string variable passed in by reference. Then, when it's done stripping out slashes, the closure is dropped and nothing new is added to the global namespace.

0 comments voice your opinion now!
closure recursive stripslashes tutorial


blog comments powered by Disqus

Similar Posts

Sanisoft Blog: Theming your CakePHP apps (V1.2)

Lineke Kerckhoffs-Willems' Blog: How to use the Symfony2 SonataAdminBundle

The Bakery: Lots of New Articles/Tutorials/Components

Symfony Blog: New in symfony 1.2: Make your Choice!

EchoDitto Labs Blog: How to Configure Eclipse PDT with Zend Server Debugger on MAMP for Drupal


Community Events

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


composer version voicesoftheelephpant symfony2 extension series api php7 application example interview library opinion framework release community introduction performance laravel podcast

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