<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>The Suburban Chicago PHP &#38; Web Development Meetup &#187; closures</title>
	<atom:link href="http://suburbanchicagophp.org/archives/tag/closures/feed" rel="self" type="application/rss+xml" />
	<link>http://suburbanchicagophp.org</link>
	<description>A monthly gathering of web professionals</description>
	<lastBuildDate>Sun, 29 Aug 2010 14:22:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>PHP is getting closures!</title>
		<link>http://suburbanchicagophp.org/archives/47</link>
		<comments>http://suburbanchicagophp.org/archives/47#comments</comments>
		<pubDate>Tue, 22 Jul 2008 12:51:48 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Language features]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[lamba]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>
		<guid isPermaLink="false">http://suburbanchicagophp.org/?p=47</guid>
		<description><![CDATA[I&#8217;ve seen very little from PHP that got me excited lately.  So, imagine how excited I am to hear that closures are coming to PHP 5.3! If you&#8217;ve done a lot with today&#8217;s popular Javascript libraries like jQuery and Prototype, you&#8217;ve no doubt come across closures.  They&#8217;re little self-contained functions that can be passed around [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen very little from PHP that got me excited lately.  So, imagine how excited I am to hear that <a href="http://www.toosweettobesour.com/2008/07/21/php-53-and-closures/">closures are coming to PHP 5.3</a>!</p>
<p>If you&#8217;ve done a lot with today&#8217;s popular Javascript libraries like jQuery and Prototype, you&#8217;ve no doubt come across closures.  They&#8217;re little self-contained functions that can be passed around like variables.  For example, jQuery&#8217;s fadeIn() method takes a function as its second parameter, and calls it when the target has faded in.  With a traditional coding style, you may have written something like this:</p>
<p> <code>
<pre>
function doStuff1()
{
	// do some stuff...
	$('#mydiv').fadeIn('normal', doStuff2);
	// do some more stuff...
}
function doStuff2()
{
	echo "hello world!";
}
</pre>
<p></code></p>
<p>This works, but there&#8217;s a visual disconnect between what happens in the middle of doStuff1() and what happens in doStuff2().  And, when you start reading doStuff2(), you don&#8217;t have any context for what&#8217;s happening (unless you left really good comments).  If doStuff2() is used in more than one place, you have a justification for keeping it a separate function.  But if it&#8217;s only used this one time, a closure is the way to go:</p>
<p><code>
<pre>
function doStuff1()
{
	// do some stuff...
	$('#mydiv').fadeIn('normal', function() {
		echo "hello world!";
	});
	// do some more stuff...
}
</pre>
<p></code></p>
<p>This code is more compact, and it makes it clear that the echo statement is related to the fadeIn() call.</p>
<p>I use closures a lot in my Javascript coding, and I&#8217;m sure I&#8217;ll be using them a lot in PHP once 5.3 is widespread.</p>
]]></content:encoded>
			<wfw:commentRss>http://suburbanchicagophp.org/archives/47/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
