<?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>Vance Lucas &#187; PHP</title>
	<atom:link href="http://www.vancelucas.com/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vancelucas.com</link>
	<description>Web Entrepreneur and Freelance PHP/Javascript Developer</description>
	<lastBuildDate>Thu, 17 Nov 2011 15:30:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>php&#124;tek 2011</title>
		<link>http://www.vancelucas.com/blog/php-tek-2011/</link>
		<comments>http://www.vancelucas.com/blog/php-tek-2011/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 14:35:23 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Speaking Engagements]]></category>
		<category><![CDATA[Titanium]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[speaking]]></category>
		<category><![CDATA[titanium]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=802</guid>
		<description><![CDATA[Chicago &#8211; May 24-27 php&#124;tek in Chicago was fun as always. It is the best PHP conference I have ever been to, which makes sense, given that it is focused solely on PHP and surrounding technologies. The best thing about the conference is the community feeling in general. You get a real sense that everyone [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; padding: 10px;"><a href="http://tek11.phparch.com/"><img src="http://www.vancelucas.com/wp-content/uploads/2011/05/tek11_SPEAKER_badge_150x150.png" alt="php|tek 2011 Speaker" /></a><br />Chicago &#8211; May 24-27</div>
<p>php|tek in Chicago was fun as always. It is the best PHP conference I have ever been to, which makes sense, given that it is focused solely on PHP and surrounding technologies. The best thing about the conference is the community feeling in general. You get a real sense that everyone there really cares about PHP and is heavily invested in it, which is good for moving the whole language and ecosystem forward.</p>
<p>I myself gave two talks &#8211; one about <a href="http://stackboxcms.com">Stackbox CMS</a>, a new CMS project I have been working on, and one about <a href="http://appcelerator.com">Apppcelerator Titanium Mobile</a> since I have been working with it a lot lately. The presentations are embedded below.<span id="more-802"></span></p>
<h3><a href="http://www.slideshare.net/vlucas/crossplatform-mobile-development-with-titanium" title="Cross-Platform Mobile Development with Titanium" target="_blank">Cross-Platform Mobile Development with Titanium</a></h3>
<div style="width:425px" id="__ss_7238077"><iframe src="http://www.slideshare.net/slideshow/embed_code/7238077" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></div>
<h3><a href="http://www.slideshare.net/vlucas/stackbox-cms-nextgeneration-content-management" title="Stackbox CMS: Next-Generation Content Management" target="_blank">Stackbox CMS: Next-Generation Content Management</a></h3>
<div style="width:425px" id="__ss_8153672"><iframe src="http://www.slideshare.net/slideshow/embed_code/8153672" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/php-tek-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Protected vs Private Scope: Arrogance, Fear, and Handcuffs</title>
		<link>http://www.vancelucas.com/blog/protected-vs-private-scope-arrogance-fear-and-handcuffs/</link>
		<comments>http://www.vancelucas.com/blog/protected-vs-private-scope-arrogance-fear-and-handcuffs/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 14:19:48 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[method scope]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[private vs protected]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=721</guid>
		<description><![CDATA[The age old private vs protected debate has been re-ignited in the PHP community recently following the decision of Doctrine2 and Symfony2 to make all class methods private until there is a very clear and proven reason to change them to protected or public. The intention is a good one &#8211; to ensure they are [...]]]></description>
			<content:encoded><![CDATA[<p>The age old private vs protected debate has been re-ignited in the PHP community recently following the decision of <a href="http://groups.google.com/group/symfony-devs/browse_thread/thread/58a0d015622c13cb">Doctrine2 and Symfony2 to make all class methods private</a> until there is a very clear and proven reason to change them to protected or public. The intention is a good one &#8211; to ensure they are providing a clear and stable API through intentional and known extension points that they can better test and support. Fabien (the creator of Symfony) points to this benefit in an <a href="http://fabien.potencier.org/article/47/pragmatism-over-theory-protected-vs-private">article of his own</a> explaining the thinking behind the decision. The primary started point of Fabien&#8217;s article and the driving thought behind this whole change and philosophy is (emphasis his):</p>
<blockquote><p><strong>Having a few well defined extension points force the developer to extend your library the right way instead of hacking your code.</strong></p></blockquote>
<p>The problem is that this kind of thinking is a slippery slope that kills the spirit of programming. It alienates the more pragmatic developers within communities. Telling other developers that you are going to force them to work with your code in some pre-determined &#8220;right way&#8221; is an incredibly arrogant statement to make.<span id="more-721"></span> Instead of letting the codebase grow organically and be modified or extended at will, you handcuff developers and send them a different message. Allow me to re-phrase it using my own words:</p>
<blockquote><p>I know the right way to use this code and I have thought of all the possible use cases. If you don&#8217;t agree, then you have to prove me wrong and wait until I either agree or figure out a better right way for you.</p></blockquote>
<p>This is the real message developers hear when internal code is private scope or marked with the final keyword &#8211; a message that they have arbitrarily limited power and ability to make changes where they need to. But it doesn&#8217;t stop there.</p>
<p>When you take the position that all methods should be private unless proven otherwise, you plant a seed of fear in the developers that use your code. Fear that whenever they may have to veer off the beaten path to meet a project requirement they won&#8217;t be able to. Fear that they might miss deadlines waiting for the &#8220;right way&#8221;  to enable the functionality they need. Fear that they might have to modify or hack the actual file or class they need to change the behavior of to achieve the functionality they want within the project deadline because they are not able to extend it.</p>
<p>Using private scope removes the fun from programming and kills the hacking spirit by creating fear through the knowledge that you will not have the ability to make changes anywhere in the codebase you need to when you need to. You are no longer in control of your own code. You were forced to submit to a <a href="http://blog.astrumfutura.com/2011/03/private-vs-protected-methods-the-debate-that-never-ends/">nanny state mentality</a> by sacrificing your freedoms to modify the code for the promise of future stability and safety. That&#8217;s not a fun place to be when you&#8217;re on the receiving end, and it&#8217;s not a policy I would ever consider enforcing with my own code. I sincerely hope this line of thinking does not proliferate within the PHP community and infect other projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/protected-vs-private-scope-arrogance-fear-and-handcuffs/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Practical Uses for PHP 5.3 Closures</title>
		<link>http://www.vancelucas.com/blog/practical-uses-for-php-5-3-closures/</link>
		<comments>http://www.vancelucas.com/blog/practical-uses-for-php-5-3-closures/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 15:19:47 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[late static binding]]></category>
		<category><![CDATA[namespaces]]></category>
		<category><![CDATA[php 5.3]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=603</guid>
		<description><![CDATA[Closures are a new language-level feature that has been added to php 5.3, along with namespaces, late static binding, and a slew of other new features, patches, and updates. If you&#8217;re like me, you might be wondering what the practical uses for these new features are before you can rightly justify diving in and using them [...]]]></description>
			<content:encoded><![CDATA[<p>Closures are a new language-level feature that has been added to php 5.3, along with namespaces, late static binding, and a slew of other new features, patches, and updates. If you&#8217;re like me, you might be wondering what the practical uses for these new features are before you can rightly justify diving in and using them in new or existing projects. I experimented a lot with closures and possible uses over the past few weeks, and came up with some compelling reasons to start using them.<br />
<span id="more-603"></span></p>
<h3>Templating</h3>
<p>Templating is perhaps the most compelling and creative use of closures that I have found, yet I haven&#8217;t seen any people or projects using closures this way. Closures are an excellent way to allow custom formatting for re-useable template widgets, like forms, datagrids, and lists. Re-useable forms and datagrids are pretty common in frameworks, because no one likes the monotony of creating a bunch of HTML forms or tables. They all seem to work great, until you have to change a few things in how they output the input fields or format cell data &#8211; then they can get a bit hairy and ugly to work with, and often require inheritance or use some obscure template syntax of their own with tokens that get string replaced and weak-to-no support for basic control structures like loops and if statements. Fabien Potencier published a <a href="http://groups.google.com/group/symfony-devs/browse_thread/thread/fb5fb9732cf5fc1e?pli=1">proof-of-concept for individual field templates</a> in Symfony2. This approach, while much more flexible than string-replaced field tokens, adds quite a bit of overhead because you now have to render one template per input field to produce a complete form. The same end result can now be easily achieved with the use of closures:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$table</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \Alloy\View\Generic\Datagrid<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'datagrid'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">posts</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">column</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #339933;">,</span> <span style="color: #000088;">$view</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">column</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Status'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #339933;">,</span> <span style="color: #000088;">$view</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">status</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">column</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Date Published'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #339933;">,</span> <span style="color: #000088;">$view</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">date_published</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dateFormat</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">date_published</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'(Unpublished)'</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$table</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>In this example, our generic &#8220;Datagrid&#8221; view accepts &#8220;$this->posts&#8221; as its data source input, and loops over it with a foreach internally. It then implicitly passes two arguments to any closure given that defines column output &#8211; &#8220;$item&#8221; &#8211; the current item in the posts collection we provided, and &#8220;$view&#8221; &#8211; the view object itself so helpers and other typical functions can be accessed.</p>
<p>The added benefits for using closures in this context are enormous. There is no additional (and limiting) pseudo-syntax to parse, and no additional item templates to render. The custom content is overridden in-line right where you want it to be (instead of being one-step removed in a separate template), and you can still use the native PHP code you know and love. The provided example is from <a href="http://cont-xt.com">Cont-xt CMS</a> built using my own <a href="http://alloyframework.org">Alloy HMVC Framework</a>.</p>
<p>Imagine how powerful and simple something like <a href="http://framework.zend.com/manual/en/zend.navigation.html">Zend_Navigation</a> and the <a href="http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.navigation">resulting navigation view helpers</a> would become with support for closure templates. You would no longer have to rely on a deep hierarchy of nested configuration arrays, custom partial templates, or complex object inter-dependencies to generate page links with your own custom code.</p>
<h3>Dynamic Code Extension</h3>
<p>Dynamically extending a class and modifying the behavior of a code block with the use of closures is the foundation of a new php 5.3 framework called <a href="http://lithify.me/">Lithium</a>. Lithium&#8217;s specific approach uses closure chains inside function bodies to allow end-users to modify core functionality without modifying the core files themselves or having to use inheritance.</p>
<p>A more extreme example uses closures to enable dynamic run-time object creation. The idea is in an article titled <a href="http://dhotson.tumblr.com/post/1167021666/php-object-oriented-programming-reinvented">PHP Object Oriented Programming Reinvented</a>. The entire object and all its functionality is created with closures. The article is a good demonstration of the power of closures, but has little practical use.</p>
<p>One of the more practical (and perhaps controversial) uses I came up with is replacing string configuration values with closures if the return values needs to be dynamic. Here&#8217;s an example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Set in base config file</span>
<span style="color: #000088;">$cfg</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'path_uploads'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cfg</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;/uploads/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$cfg</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Set dynamically by database value from logged-in user later in your application</span>
<span style="color: #000088;">$cfg</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">74</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This way, the &#8216;path_uploads&#8217; config value will not have to be changed when the &#8216;user_id&#8217; config value is. The closure will cause the config value to always be evaluated when called, and will always use the current &#8216;user_id&#8217; value, so it will never be &#8220;out of date&#8221;. This, of course, requires you to have a standard way to retrieve config values from named keys, because closures can&#8217;t just be automatically converted to a string by themselves, and do have to be called a different way (like functions).</p>
<p>This is the only use that comes with a warning: beware how far down this road you travel. Dynamic code extension provides a lot of flexibility, but comes with the downside of code obfuscation and performance penalties. You are essentially adding class methods and modifying code behavior in places other than the code itself, which can lead to confusion when trying to trace code execution. Stack traces and development toolbars can help here, and using an opcode cache like APC can minimize the performance penalty.</p>
<h3>Delayed Execution</h3>
<p>Closures are a great tool to use anywhere you need to delay PHP code execution until a later time. A great example of this use is for a job queue system with multiple workers. Using closures, you can execute any arbitrary PHP code you need to without conforming to a specific structure &#8212; there is no need to create new classes or functions with set names determined by naming conventions, and no need to put &#8220;worker classes&#8221; in any specific place in the filesystem. Your worker task can be passed around and executed in parallel at will by the job queue.</p>
<p>Example: <a href="http://github.com/kore/njq">PHP Native Job Queue</a>.</p>
<h3>Caching</h3>
<p>Using closures for caching is a bit of an extension of the delayed execution idea. Consider a cached block of code inside a view template using a closure:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cache</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$view</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #666666; font-style: italic;">// Expensive external HTTP request</span>
    <span style="color: #000088;">$blogRss</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'feedReader'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://github.com/zendframework/zf2/commits/master.atom'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$widget</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \MyApp\View\Generic\FeedList<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'feedlist'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$widget</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feedContent</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$blogRss</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'atom'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$widget</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">?&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'github_zf2_commits'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Using a closure here offers two advantages over the typical &#8216;beginCache&#8217;, &#8216;&#8230;&#8217;, &#8216;endCache&#8217; type calls that are more prevalent in pre-5.3 code. The first benefit is that through the use of a closure, our code block is contained in a variable before it is even executed. This allows us to use a cache backend like Memcache without having to use output buffering at all, saving us a tiny bit of overhead. The second big benefit is that executing our code chunk is entirely optional, without manually checking the cache first. This second benefit could also allow you to disable rendering of certain cached content completely if you need it, without any code changes in your view templates. Heavy-load or traffic spike scenarios come to mind as possible candidates for this functionality. Imagine being able to make a small configuration change to skip certain code blocks like $cache->disable(&#8216;github_zf2_commits&#8217;) to serve a &#8220;lite&#8221; version of your site when you need all the server resources you can get.</p>
<h3>Convenience</h3>
<p>This may sound like a bit of a cop-out reason, but using closures in some cases really does make things a lot easier, and truly better. Consider the case where you have to use a one-off function to apply some sort of custom filtering logic to an array or collection of objects. With closures, you can just specify the logic in-place right where you need it instead of having to create a new function for the job in a separate location and having to figure out where to put it in your application, and then how to call it. It produces the same result in fewer lines of code with no side-effects (like having to make a global function).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Collection of entities</span>
<span style="color: #000088;">$objCollection</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #000000; font-weight: bold;">new</span> Entity<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #000000; font-weight: bold;">new</span> Entity<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #000000; font-weight: bold;">new</span> EntityRelation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #000000; font-weight: bold;">new</span> OtherRandomJunk<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get only Entity objects</span>
<span style="color: #000088;">$entitiesOnly</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_filter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$objCollection</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span> instanceof Entity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>In the above example, it may not make sense to create a separate named or global function for this collection filtering, because it may only ever be used in one place. If this is the case, it makes sense to use a closure, and makes the code more concise and readable because everything is all in one place.</p>
<h3>Summary</h3>
<p>Closures are a game-changer for PHP all by themselves. Throw namespaces and late static binding in the mix as well, and PHP 5.3 reaches a level of power and dynamic flexibility that PHP has never been able to reach before. If you have been sitting on the sidelines, stuck in PHP 5.2 land &#8211; you desperately need to upgrade. This is the future of PHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/practical-uses-for-php-5-3-closures/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Get Only Public Class Properties for the Current Class in PHP</title>
		<link>http://www.vancelucas.com/blog/get-only-public-class-properties-for-current-class-in-php/</link>
		<comments>http://www.vancelucas.com/blog/get-only-public-class-properties-for-current-class-in-php/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 23:06:01 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[class properties]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[oo]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=525</guid>
		<description><![CDATA[PHP provides two built-in functions to retrieve properties of a given class &#8211; get_object_vars and get_class_vars. Both these functions behave the same exact way, one taking an object as a variable and the other taking a string class name. The tricky thing about the two functions is that they behave differently depending on the call [...]]]></description>
			<content:encoded><![CDATA[<p>PHP provides two built-in functions to retrieve properties of a given class &#8211; <a href="http://php.net/get_object_vars">get_object_vars</a> and <a href="http://php.net/get_class_vars">get_class_vars</a>. Both these functions behave the same exact way, one taking an object as a variable and the other taking a string class name. The tricky thing about the two functions is that they behave differently depending on the call scope, returning all of the class variables available within the called scope. So if you call either function within the current class you need properties from, all properties are returned &#8211; public, protected, and private &#8211; because the current scope has access to them all. This makes seemingly simple things like returning all the public properties within the current class a bit of a pain if you want to keep the code inside the class itself.<br />
<span id="more-525"></span><br />
The obvious solution is to use the functions from a different call scope, which means either moving the call outside the class to the implementation code (yuck), or creating a new function outside the class for it. A lot of suggestions in the PHP manual say to create a new function below the class definition and call it within the class (kind of a proxy function as a workaround), but that seems tacky. Luckily, PHP also provides another way to get a new call scope: <a href="http://php.net/manual/en/functions.anonymous.php">anonymous functions</a> (and <em>closures</em> as of PHP 5.3).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> BobUser
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bob'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$publicFlag</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$internalFlag</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getFields<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$getFields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$obj'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'return get_object_vars($obj);'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$getFields</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Returns only 'name' and 'publicFlag'</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We can also do this the PHP 5.3 way with a much nicer-looking closure:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> BobUser
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// ...</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getFields<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$getFields</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #990000;">get_object_vars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$getFields</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/get-only-public-class-properties-for-current-class-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Why WordPress Should Not Have Won the Open Source CMS Award</title>
		<link>http://www.vancelucas.com/blog/wordpress-and-the-open-source-cms-award/</link>
		<comments>http://www.vancelucas.com/blog/wordpress-and-the-open-source-cms-award/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 19:10:26 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[awards]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Joomla]]></category>
		<category><![CDATA[MODx]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[open source cms awards]]></category>
		<category><![CDATA[SilverStripe]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=498</guid>
		<description><![CDATA[Packt Publishing announced the winners for their annual Open Source CMS Award in November, and since then I have been a bit disturbed that the 2009 winner was WordPress. My first reaction was this: &#8220;&#8230; So a blogging platform won the content management system award? How sad is that?&#8221; My knee-jerk &#8220;how sad is that?&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Packt Publishing announced the winners for their annual <a href="http://www.packtpub.com/award">Open Source CMS Award</a> in November, and since then I have been a bit disturbed that the 2009 <a href="http://wordpress.org/development/2009/11/wordpress-wins-cms-award/">winner was WordPress</a>. My first reaction was this:</p>
<blockquote><p>&#8220;&#8230; So a <em>blogging platform</em> won the <em>content management system</em> award? How sad is that?&#8221;</p></blockquote>
<p>My knee-jerk &#8220;how sad is that?&#8221; reaction comes not because I don&#8217;t think WordPress is worthy, but because of what it implies about the state of other open source CMS projects. The reaction comes from the fact that <em>a </em><strong>blogging platform is kicking your CMS&#8217;s ass in its own category</strong>.</p>
<p><span id="more-498"></span></p>
<p>WordPress bridges both the blogging and CMS categories due to the &#8216;Pages&#8217; feature, and is extremely useful for managing a blog-focused website. Mostly. That is, until you want to do something that a CMS should be good at, like have an event calendar, custom form, photo gallery, etc. &#8211; which is why WordPress is not focused on being a CMS in the first place. Yet <em>it does such a better job at the basic things</em> like creating new pages, tagging, categorizing, comments, and having custom SEO-friendly URLs out of the box that it edged out other software projects like <del><a href="http://drupal.org/">Drupal</a></del> <a href="http://modxcms.com/">MODx</a> and <del><a href="http://www.joomla.org/">Joomla!</a></del> <a href="http://www.silverstripe.com/">SilverStripe</a> whose sole focus is content management. Sad indeed.</p>
<p>The fact that I can go through <a href="http://php.opensourcecms.com/scripts/show.php?catid=1&amp;cat=CMS%20/%20Portals">literally hundreds</a> of open source content management systems and still end up settling on WordPress because I know it&#8217;s the only one that won&#8217;t totally confuse my client is what&#8217;s sad. Usability and ease of use matter. They are the number one feature to the end user. If you&#8217;re involved in a CMS project, you need to do better. A <em>lot</em> better. <strong>Right now</strong>.</p>
<p><strong>UPDATE</strong>: Some commenters have pointed out that the awards website has a specific rule:</p>
<blockquote><p>Previous winners of the Overall category are not eligible for the Overall category in 2009. Previous winners compete amongst one another in a separate Hall of Fame category designed specifically for them.</p></blockquote>
<p>Since both Drupal and Joomla! have won the award previously and thus were automatically excluded, I replaced their names with the CMS projects that were 2nd and 3rd behind WordPress (MODx and SilverStripe) instead. The premise of the post still holds true.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/wordpress-and-the-open-source-cms-award/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>CodeWorks 2009 Dallas</title>
		<link>http://www.vancelucas.com/blog/codeworks-2009-dallas/</link>
		<comments>http://www.vancelucas.com/blog/codeworks-2009-dallas/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 05:03:52 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Speaking Engagements]]></category>
		<category><![CDATA[codeworks]]></category>
		<category><![CDATA[cw09]]></category>
		<category><![CDATA[speaking]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=436</guid>
		<description><![CDATA[I was fortunate enough to be selected as the regional speaker for the Dallas CodeWorks 2009 stop by the Dallas PHP User Group through a community voting and selection process. My talk was entitled Object Oriented Apologetics, and was essentially about letting people know what good object-oriented code is, when to use it, how to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cw.mtacon.com/schedule/speakers#vance_lucas"><img class="alignright" src="http://www.vancelucas.com/wp-content/uploads/2009/09/CW09_Speaker.png" alt="CodeWorks 2009 Speaker" width="150" height="200" /></a><br />
I was fortunate enough to be selected as the regional speaker for the Dallas <a href="http://cw.mtacon.com/">CodeWorks 2009</a> stop by the <a href="http://dallasphp.org">Dallas PHP User Group</a> through a community voting and selection process. My talk was entitled <strong>Object Oriented Apologetics</strong>, and was essentially about letting people know what good object-oriented code is, when to use it, how to use it, and more specifically <em>why</em> to use it over traditional procedural PHP code.<span id="more-436"></span></p>
<h3>Object Oriented Apologetics</h3>
<blockquote><p>In defense of object-oriented programming &#8211; How and why you should use object oriented programming for your next project.This talk is for PHP programmers who are just learning about object oriented code, who cling to old excuses(&#8220;object oriented code is slower&#8221;), or who are otherwise unconvinced of its usefulness. Concrete real-world examples of commonscenarios and challenges that programmers face will be presented, and how taking an object oriented approach is better than a proceduralone in most cases. Copious code examples in both object oriented and procedural approaches will be provided throughout, and thedifferences and benefits of the object oriented approach will be explained.</p></blockquote>
<div id="__ss_2092025" style="width: 425px; text-align: left;"><object style="margin:0px" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=objectorientedapologetics-090929144850-phpapp02&amp;rel=0&amp;stripped_title=object-oriented-apologetics" /><param name="allowfullscreen" value="true" /><embed style="margin:0px" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=objectorientedapologetics-090929144850-phpapp02&amp;rel=0&amp;stripped_title=object-oriented-apologetics" allowscriptaccess="always" allowfullscreen="true"></embed></object></div>
<p><a href="http://www.slideshare.net/vlucas/object-oriented-apologetics">Download Object Oriented Apologetics on SlideShare</a></p>
<p>If you were in the talk, <a href="http://joind.in/talk/view/722">please rate it on Joind.in</a></p>
<h3>The CodeWorks Experience</h3>
<p>All in all, the CodeWorks roadshow Dallas stop was much smaller than I expected. There were about 20 people in the talk I gave. I suppose it was both a good a bad thing. On one hand, I had a lot of fun connecting with the other speakers and attendees on a more personal level than I would have had the opportunity to do otherwise. I met a lot of new people in the PHP community that I will probably stay connected with on some level, even if it is just <a href="http://twitter.com">Twitter</a> and IRC. We had a lot of fun the night before the presentation day eating together and hanging out.</p>
<p>On the other hand, I know that as a business, the relatively low attendance levels coupled with the high travel expenses could mean that something like this can&#8217;t happen again, which is a shame. This was one of the best efforts I have seen in a while to really lower the price of the conference for attendees by bringing the speakers directly to their cities or at least ones that are close by. Going to <a href="http://www.zendcon.com">ZendCon</a>, for instance, could easily cost up to $2,500 for the whole trip with airfare, hotel stays, and food, if not more.</p>
<p>The bottom line here is that CodeWorks was a good conference that offered a great value for your money. I had a great time meeting and connecting with new people and finally meeting people in real life that I had been communicating with for years. I learned some new things and finally got the kick in the pants I needed to jump into <a href="http://en.wikipedia.org/wiki/Test-driven_development">Test Driven Development</a>, thanks to <a href="http://blog.casey-sweat.us/">Jason Sweat&#8217;</a>s TDD tutorial and hand-holding.</p>
<p>Now I&#8217;m just looking forward to php|tek in May 2010.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/codeworks-2009-dallas/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The One Character Block Comment</title>
		<link>http://www.vancelucas.com/blog/the-one-character-block-comment/</link>
		<comments>http://www.vancelucas.com/blog/the-one-character-block-comment/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 14:58:10 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[code comments]]></category>
		<category><![CDATA[comments]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=401</guid>
		<description><![CDATA[When debugging, I often find that I have to comment and un-comment a block of code several times during the process of trying to find out what&#8217;s going on. That used to mean typing and deleting comment block characters repetitively, but not anymore. Here&#8217;s a simple solution to that problem: Comment or un-comment an entire [...]]]></description>
			<content:encoded><![CDATA[<p>When debugging, I often find that I have to comment and un-comment a block of code several times during the process of trying to find out what&#8217;s going on. That used to mean typing and deleting comment block characters repetitively, but not anymore. Here&#8217;s a simple solution to that problem: Comment or un-comment an entire code block of code by typing or deleting a single character.</p>
<p>I was able to arrive at this solution by combining the one-line comment with the comment block in a way that takes advantage of the rules the different types of comments have to follow.<br />
<span id="more-401"></span></p>
<h3>The One-Line Comment</h3>
<p>One-line comment rules dictate that everything after the comment characters must be ignored for the rest of that line. They look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// My code below</span>
<span style="color: #000088;">$someVar</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;foo&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;bar&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;blah&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;code&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$someVar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/code&gt;&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>The Block Comment</h3>
<p>Block comment rules dictate that once the beginning characters are started, everything up until the ending characters is ignored. They look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* My code below
$someVar = array(&quot;foo&quot;, &quot;bar&quot;, &quot;blah&quot;);
echo &quot;&lt;code&gt;&quot;;
print_r($someVar);
echo &quot;&lt;/code&gt;&quot;;
*/</span></pre></td></tr></table></div>

<h3>Combining The Two: The Best of Both Worlds</h3>
<p>Using both those comment style rules, we can combine the two comment styles in a way that will allow us to comment and un-comment a block of code with by adding or deleting a single character. The trick is to make both the beginning and ending lines both single-line AND block style comments, like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//* My code below</span>
<span style="color: #000088;">$someVar</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;foo&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;bar&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;blah&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;code&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$someVar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/code&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// */</span></pre></td></tr></table></div>

<p>In the above example, you notice that the code will still run &#8211; it&#8217;s not commented out because the first line is following the rules of the single-line comment &#8211; ignoring the block comment declaration on the same line. By removing the first backslash at the beginning of the block, we can comment out the entire code block by enabling the block comment style instead of the single-line style. The last single-comment line is ignored because the block comment rules ignore everything up until the end block comment declaration at the end of the line:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* My code below
$someVar = array(&quot;foo&quot;, &quot;bar&quot;, &quot;blah&quot;);
echo &quot;&lt;code&gt;&quot;;
print_r($someVar);
echo &quot;&lt;/code&gt;&quot;;
// */</span></pre></td></tr></table></div>

<p>So a single character &#8211; a backslash at the very beginning of the block declaration can now comment or un-comment the entire block by switching the comment rules back and forth between single-line and block style. The code examples provided are in PHP, but this trick will work with any language that supports both single-line and block style comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/the-one-character-block-comment/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>OKC PHP User Group Reboot</title>
		<link>http://www.vancelucas.com/blog/okc-php-user-group-reboot/</link>
		<comments>http://www.vancelucas.com/blog/okc-php-user-group-reboot/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 14:58:00 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Speaking Engagements]]></category>
		<category><![CDATA[okcphp]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[PHP DataMapper]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=368</guid>
		<description><![CDATA[The local Oklahoma City PHP User Group is re-starting with the okcCoCo as the new venue. The new meetings will be on the second Tuesday of each month, starting with Tuesday, June 09, 2009 at 6:30pm as the first official meeting. Visit the official OKC PHP User Group website to register for meeting reminders and [...]]]></description>
			<content:encoded><![CDATA[<p>The local Oklahoma City PHP User Group is re-starting with the <a href="http://okccoco.com">okcCoCo</a> as the new venue. The new meetings will be on the second Tuesday of each month, starting with <strong>Tuesday, June 09, 2009 at 6:30pm</strong> as the first official meeting. Visit the official <a href="http://phpokc.net">OKC PHP User Group website</a> to register for meeting reminders and to connect with other local PHP developers.</p>
<p>I will be presenting my talk on<strong> Building a Data Mapper with PHP5 and the Standard PHP Library</strong>, followed by a discussion on ORMs and whatever else comes up. The presentation will cover all the thought processes, goals, theories, and actual code that goes into building an ORM (or really any other larger project that requires more advance planning). The project that was the basis of this presentation is <a href="http://phpdatamapper.com">phpDataMapper</a> &#8211; an open-source PHP5 data mapper ORM layer that I started in the fall of 2008. It now powers the model layer of <a title="InvoiceMore - Online Billing and Invoicing" href="http://www.invoicemore.com">InvoiceMore</a>, a live web application I launched in March 2009.</p>
<p>This is a presentation I have given before at Tulsa TechFest.</p>
<p><strong><a href="http://blip.tv/file/2249586/">Watch the video of this presentation online</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/okc-php-user-group-reboot/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introducing&#8230; PHP DataMapper!</title>
		<link>http://www.vancelucas.com/blog/introducing-php-datamapper/</link>
		<comments>http://www.vancelucas.com/blog/introducing-php-datamapper/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 17:11:58 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[PHP DataMapper]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=212</guid>
		<description><![CDATA[PHP DataMapper is an open-source project I&#8217;ve been building and working on for a little while now.  It&#8217;s a lightweight Object-Relational Mapper based on the Data Mapper design pattern, setup using one mapper per table.  The primary goal is to make database access one of the easiest parts of building your application instead of the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://phpdatamapper.com">PHP DataMapper</a> is an open-source project I&#8217;ve been building and working on for a little while now.  It&#8217;s a lightweight <a href="http://en.wikipedia.org/wiki/Object-relational_mapping">Object-Relational Mapper</a> based on the Data Mapper design pattern, setup using one mapper per table.  The primary goal is to make database access one of the easiest parts of building your application instead of the most tedious, and for PHP DataMapper itself to have no dependencies outside the default PHP5 installation so it can be used anywhere, in any application (no frameworks required!).</p>
<p>The project itself hasn&#8217;t changed too much recently, but I decided to finally formally introduce this project because I finally got some time to write some decent documentation on how to use PHP DataMapper in in your own application.  Head on over to the <a href="http://phpdatamapper.com">PHP DataMapper</a> page to check it out, or just get right into the good stuff with the <a href="http://phpdatamapper.com/documentation/getting-started/">Getting Started</a> tutorial or the  <a href="http://phpdatamapper.com/documentation/usage/finders/">Usage &#8211; Finders</a> example.</p>
<p>More updates and documentation will be coming soon.  If you&#8217;re interested in learning more about the project or contributing, please <a href="http://groups.google.com/group/phpdatamapper">join the Google Group</a>.</p>
<p><strong>UPDATE:</strong> Links have been updated to the new home for the project &#8211; <a href="http://phpdatamapper.com">phpdatamapper.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/introducing-php-datamapper/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Early Performance Benchmarking is a Disease</title>
		<link>http://www.vancelucas.com/blog/early-performance-benchmarking-is-a-disease/</link>
		<comments>http://www.vancelucas.com/blog/early-performance-benchmarking-is-a-disease/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 19:46:19 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[benchmarking]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[profiling]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=114</guid>
		<description><![CDATA[Benchmarking and performance concerns should be one of the last things you address while building your application, but it seems as though, in the PHP community especially, it&#8217;s often one of the first things novice developers think about. Any PHP developer who&#8217;s been in the community for a while has heard preposterous claims like &#8220;use [...]]]></description>
			<content:encoded><![CDATA[<p>Benchmarking and performance concerns should be one of the <em>last</em> things you address while building your application, but it seems as though, in the PHP community especially, it&#8217;s often one of the <em>first</em> things novice developers think about.</p>
<p>Any PHP developer who&#8217;s been in the community for a while <a href="http://reinholdweber.com/?p=3">has heard</a> preposterous claims like &#8220;use single quotes (&#8216;) for strings instead of double quotes (&#8220;), because it&#8217;s faster&#8221;.  That is, faster over the 100,000 or so iterations it took the tester to generate a number sufficiently large enough to justify the claim, with a particular version of PHP, in a particular development environment in which it was tested.<span id="more-114"></span></p>
<p>These articles are then followed up with <a href="http://www.chazzuka.com/blog/?p=163">other</a> <a href="http://blogs.digitss.com/php/php-performance-improvement-tips/">posts</a> that only serve to perpetuate and solidify the original and invalid performance claims.  Articles like these are like a plague to the PHP community, spreading around and steering novice developers in the wrong direction, concerning them with the wrong things.  Chris Vincent recently released <a href="http://www.phpbench.com/">PHPBench.com</a> &#8211; a website that benchmarks chunks of related PHP code against each other to compare the speeds.  His goal was just a simple discovery of what code is actually fastest, and although it does yield a few interesting results, I have to wonder if it even matters.  If the tests prove anything at all, it&#8217;s that the specific syntax you choose <em>doesn&#8217;t</em> matter.  Why? Because it shows that newer PHP versions (he runs it on PHP 5.2+ where most of the previous articles were based on PHP 4.x) have been corrected and optimized to fix any performance discrepencies that there may have been in the past.  In the &#8220;double (&#8220;) vs. single (&#8216;) quotes&#8221; test, Chris concludes:</p>
<blockquote><p>&#8220;In today&#8217;s versions of PHP it looks like this argument has been satisfied on both sides of the line. Lets all join together in harmony in this one!&#8221;</p></blockquote>
<p>Similarly, the differences in the &#8220;echo vs. print&#8221; and &#8220;for vs. while&#8221; tests are so close in speed (and again remember, this is over 1,000 iterations) that you&#8217;re just better off using which ever one is a better fit the for job you&#8217;re doing.</p>
<h3>Optimize for Performance AFTER You Code</h3>
<p>The true way to optimize your code to run faster is to worry about optimization <em>after</em> you code.  This is, of course, because the <em>real </em>bottlenecks in your code can only be identified <em>after</em> the code is already written.  When put into simplified steps, the development and optimization process would then look something like this:</p>
<ol>
<li>Write code</li>
<li>Run it for a while until you (or your users) start to experience noticeable slowdowns or you begin to reach the capacity of the hardware you&#8217;re running on</li>
<li><a href="http://www.sitepoint.com/blogs/2007/04/23/faster-php-apps-profile-your-code-with-xdebug/">Profile</a> <a href="http://devzone.zend.com/article/2899-Profiling-PHP-Applications-With-xdebug">your</a> <a href="http://www.pseudocoder.com/archives/2007/04/24/how-to-really-use-xdebug-to-speed-up-your-app/">code</a> to identify where the <em>real </em>bottlenecks are</li>
<li>Re-factor and make adjustments to your code to fix those bottlenecks</li>
<li>Go back to step 2</li>
</ol>
<p>Now that&#8217;s not to say that performance concerns should be <em>completely</em> discarded when writing your code &#8211; experienced developers will automatically make code and design decisions based on their experience that will have a beneficial impact on performance while they&#8217;re writing the code.  This just means that it should never be your <em>primary </em>focus when developing your application, and that you should never be overly concerned about it until it&#8217;s actually a problem.</p>
<h3>The Impact on Your Code</h3>
<p>So the real difference here is that when you listen to benchmarks and have performance as a high priority immediately, you end up making bad design decisions and waste time worrying and doing things that may not even affect performance at all in the end.  So instead, <em>focus on your users</em>, and do what you can to make their lives easier, no matter what you think ahead of time the performance impact may be.  If it becomes a problem in the future, you can turn your focus to the specific problem and fix your code where the problems actually are.</p>
<h3>Conclusion</h3>
<p>Put aside your worries about performance and <strong>just build it</strong>.  Would you rather have 10,000 users using a website with performance problems that you have to fix or 100 users using a website that is half as useful but runs 10% faster because you spent all your time focusing on performance &#8220;tips&#8221; when they may not even have an impact on performance at all?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/early-performance-benchmarking-is-a-disease/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

