News Feed
Sections




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

Lorna Mitchell's Blog:
Callbacks in PHP
February 14, 2011 @ 13:41:28

Lorna Mitchell has a new post to her blog today looking at a very handy piece of PHP functionality sprinkled around in different functions - using callbacks to handle complicated processing.

Recently I was working on something and I wanted to call an object method as a callback, but got confused when I realised the method had been caused statically. This was caused by my inability to RTFM and I wondered how I'd come so far without actually coming across the many and varied things you can pass into any place a callback is needed.

Besides the normal callback functions you can put in something like call_user_func, she also mentions something a bit more powerful - passing in an array that contains a pointer to an object and a method inside it. This ability allows you to keep your OOP encapsulation intact without having to make global functions. In PHP 5.3, there's even some of the PHP functions that use call backs that will allow you to use closures/anonymous functions without even having to make a separate function.

0 comments voice your opinion now!
callback calluserfunc function object closure anonymous


blog comments powered by Disqus

Similar Posts

Jani Hartikainen's Blog: Using models as criteria objects for querying the database

Zend Developer Zone: Accessing DB2 Data Inside of i5/OS

DevShed: Using the Sleep and Wakeup Functions to Serialize Objects in PHP (Part 2)

Stubbles Blog: Extending objects with new methods at runtime

Ilia Alshanetsky's Blog: Filter Extension Revamped (and PHP 5.2 news)


Community Events





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


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

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