<?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>Juozas devBlog &#187; php 5.3</title>
	<atom:link href="http://dev.juokaz.com/tag/php-53/feed" rel="self" type="application/rss+xml" />
	<link>http://dev.juokaz.com</link>
	<description>Random ideas, scripts and facts</description>
	<lastBuildDate>Mon, 22 Mar 2010 10:48:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Don&#8217;t be afraid of PHP 5.3</title>
		<link>http://dev.juokaz.com/php/dont-be-afraid-of-php-5-3</link>
		<comments>http://dev.juokaz.com/php/dont-be-afraid-of-php-5-3#comments</comments>
		<pubDate>Tue, 02 Mar 2010 12:37:34 +0000</pubDate>
		<dc:creator>Juozas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[backwards compatibility]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[php 5.3]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://dev.juokaz.com/?p=977</guid>
		<description><![CDATA[While attending PHPUK conference in London, I noticed how much talk there is about PHP 5.3 and &#8220;when to upgrade?&#8221;, there was even a presentation about that. Because I have been using PHP 5.3 for more than half a year, I decided to share my views on this topic. This topic is very important as [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://dev.juokaz.com/wp-content/uploads/2009/05/osoft_1490922690php-logo-300x158.png" alt="" title="osoft_1490922690php-logo" width="150" height="79" class="alignnone size-medium wp-image-800" style="float: left; margin-right: 10px;" />While attending <a href="http://www.phpconference.co.uk/">PHPUK conference</a> in London, I noticed how much talk there is about PHP 5.3 and &#8220;when to upgrade?&#8221;, there was even a presentation about that. Because I have been using PHP 5.3 for more than half a year, I decided to share my views on this topic. This topic is very important as the earlier PHP 5.3 is adopted, the sooner second iteration of frameworks can be released (story for <a href="http://www.symfony-project.org/blog/2009/10/27/why-will-symfony-2-0-finally-use-php-5-3">Symfony</a>).</p>
<h5>New features</h5>
<p>PHP 5.3 includes a lot of <a href="http://php.net/releases/5_3_0.php">new features</a>. Some of them are new language features like namespaces, closures, exceptions chaining, jump labels etc., and even though these are very recommended to learn, they are not required. You can continue to write code as you are used to and chances are that it will still work (more about that in <em>Legacy code</em>). </p>
<p>What is important from new features is fixes are enhancements. For example new garbage collector and other fixes reduce memory usage and increases performance. There are also some new extensions like <a href="http://php.net/phar">phar</a>, <a href="http://php.net/sqlite3">sqlite3</a> and <a href="http://php.net/fileinfo">fileinfo</a> and some libraries (like mysql or openssl) have some major improvements. Finally, Windows support is improved even further and now is expected to be even more production-ready.</p>
<h5>Legacy code</h5>
<p>Apparently the biggest problem is with legacy applications &#8211; somehow everyone just decided that because of all these new features, everything should break. If you&#8217;d look at backward incompatibility list <a href="http://php.net/manual/en/migration53.incompatible.php">here</a>, you notice that not that much has changed. Or in other words &#8211; if your code was <em>&#8220;correct&#8221;</em> before upgrade, it will work fine with PHP 5.3 too. For example static and/or private setters, ereg and some more other features shouldn&#8217;t have been used in a first place as manual clearly stated that.</p>
<p>Personally I have upgraded around 10 projects to run on PHP 5.3, each took less than an hour. On my development machine I also have <a href="http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting">strict</a> error reporting level so I even had to remove marked-as-deprecated code, but for larger part of code everything worked fine. Furthermore, some of that code has been written using PHP 4, a couple years ago, and it still worked just fine. </p>
<h5>Debian&#8230;</h5>
<p>As far as I&#8217;m aware of, main linux distros like Debian or Red Hat do not have PHP 5.3 in their <em>stable</em> repositories, which makes upgrading potentially very hard or impossible. I have come across this before &#8211; sysadmins do not want to install anything outside from stable, so the only option is to wait (that happened to me when PHP 5 was still not well adopted). This is probably the only reasonable argument to not switch to PHP 5.3, but only if you don&#8217;t have option to switch servers.</p>
<p>I&#8217;m lucky with this problem, because I do not administer servers, but still can request for any PHP version I want. If you do not have this option, maybe it&#8217;s time to switch hosting server provider? There can be different situations, but software version shouldn&#8217;t be a limiting factor, especially when new version is available and known to be stable enough. You can even use <a href="http://www.top-web-solutions.com/apache-with-multiple-php-versions.html">multiple PHP versions</a> if switching server would require testing a lot of applications.</p>
<h5>Why you should be using PHP 5.3 right now</h5>
<p>Firstly because it has those new features, which mean that you can start to use them as an early adopter and benefit later. All <em>second iteration</em> frameworks (Zend Framework 2.0, <a href="http://symfony-reloaded.org/">Symfony 2.0</a>, Lithium etc.) coming out late this year will use PHP 5.3 extensively, so knowing how namespaces work (I&#8217;d say they are the ones you need to look first) and how to utilize closures will mean that you can get going very quickly. </p>
<p><a href="http://www.doctrine-project.org/documentation/2_0/en">Doctrine 2.0</a> is probably the best example of why you should learn PHP 5.3 now &#8211; most of its features could be written in older versions too, but not as clean and easy to understand. And it&#8217;s already in <em>alpha</em> stage, so stable version might be coming out very soon and yet again &#8211; if you want to stay on top of your game, you need to know how it works and how to leverage all new features. </p>
<p>As mentioned above, because of new garbage collector implementation PHP 5.3 performs much better (<a href="http://schlueters.de/blog/archives/68-PHP-5.3-Up-to-30-performance-win.html">benchmarks</a>). From my personal tests I have noticed that Zend Framework uses much less memory, just because there is less <a href="http://en.wikipedia.org/wiki/Memory_leak">memory leaks</a>, Doctrine of course gets a big <a href="http://dev.juokaz.com/php/zend-framework-and-doctrine-part-3">speed up</a> too.</p>
<h5>Conclusion</h5>
<p>I&#8217;m yet unsure what is all that buzz about &#8211; PHP 5.3 is stable, way faster than previous versions and works with legacy code just fine. Considering that it has new core features, which will be expected from developers to be known in just a few months, I don&#8217;t see a reason why you shouldn&#8217;t use it. And if you have any questions you can just ask me directly on <a href="http://twitter.com/juokaz">twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.juokaz.com/php/dont-be-afraid-of-php-5-3/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Lambda functions are coming to PHP</title>
		<link>http://dev.juokaz.com/php/lambda-function-coming-to-php</link>
		<comments>http://dev.juokaz.com/php/lambda-function-coming-to-php#comments</comments>
		<pubDate>Thu, 26 Mar 2009 19:56:34 +0000</pubDate>
		<dc:creator>Juozas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[anonymous function]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[lambda]]></category>
		<category><![CDATA[php 5.3]]></category>

		<guid isPermaLink="false">http://dev.juokaz.com/?p=434</guid>
		<description><![CDATA[Only some days ago PHP.net introduced 5.3.0RC1 version, but future features have been known for quite a while. Namespaces and lambda functions (+ closures) are most anticipated, because they&#8217;ll increase flexibility and good-looks of code a lot. Today I&#8217;m going to try to prove why lambda functions are so useful.
Because of &#8220;Functional Programming&#8221; course I [...]]]></description>
			<content:encoded><![CDATA[<p>Only some days ago PHP.net introduced <a href="http://www.php.net/archive/2009.php#id2009-03-24-1">5.3.0RC1</a> version, but future features have been known for quite a while. Namespaces and <a href="http://en.wikipedia.org/wiki/Lambda_function">lambda functions</a> (+ closures) are most anticipated, because they&#8217;ll increase flexibility and good-looks of code a lot. Today I&#8217;m going to try to prove why lambda functions are so useful.</p>
<p>Because of &#8220;Functional Programming&#8221; course I had in <a href="http://www.ed.ac.uk">university</a>, I love lambda functions. At first they seemed a little bit strange, but hey &#8211; in <a href="http://www.haskell.org/">Haskell</a> you write:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">Input: <span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span>\x <span style="color: #339933; font-weight: bold;">=&gt;</span> x<span style="color: #339933; font-weight: bold;">*</span><span style="color: red;">3</span><span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">3</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">4</span><span style="color: green;">&#93;</span>
Output: <span style="color: green;">&#91;</span><span style="color: red;">3</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">6</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">9</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">12</span><span style="color: green;">&#93;</span></pre></div></div>

<p>No need to create for loops (which doesn&#8217;t exists in Haskell at all) and code is much more flexible. Functional languages allows creating functions which accepts functions as arguments, not only integers or floats. That&#8217;s why most functions are very short, but are very easily connectable together. </p>
<p>I think one the best examples of lambda functions usefulness is sorting. Image this scenario: <em>$books</em> <a href="http://docs.php.net/manual/en/class.arrayobject.php">collection</a> holds books information and you need to sort it by title; author; publish year and author; publish city and title. How you are going to do it? It&#8217;s easy and you probably would write something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Sort by title</span>
<span style="color: #000088;">$books</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sortByTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ASC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Sort by publisher year, author</span>
<span style="color: #000088;">$books</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sortByPublishYear</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DESC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sortByAuthor</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ASC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>However, it looks good and does work just fine, but it&#8217;s not very practical &#8211; you need to create functions for all keywords (title, author, publish year, etc.). You may argue, that __call() can be used and that&#8217;s absolutely true, but it&#8217;s even harder to maintain and code it, still usable though. </p>
<p>Nevertheless, 5.3 version of <a href="http://dev.juokaz.com/category/php">PHP</a> introduces lambda functions (also called <a href="http://docs.php.net/functions.anonymous">anonymous functions</a>), which can simplify your work a lot (I haven&#8217;t tried running this code):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Sort by book title</span>
<span style="color: #000088;">$books</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sort</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;">$book1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$book2</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">strcmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$book1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">,</span> <span style="color: #000088;">$book2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><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>
&nbsp;
<span style="color: #666666; font-style: italic;">// Sort by publisher year, author</span>
<span style="color: #000088;">$books</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sort</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;">$book1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$book2</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$book1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">publish_year</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$book2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">publish_year</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #990000;">strcmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$book1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">author</span><span style="color: #339933;">,</span> <span style="color: #000088;">$book2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">author</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">strcmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$book2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">publish_year</span><span style="color: #339933;">,</span> <span style="color: #000088;">$book1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">publish_year</span><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></div></div>

<p>It&#8217;s a little bit harder to read and maybe understand, but basically you can pass whatever comparison function you&#8217;d like. Sort function can use simple for-loop-inside-for-loop or <a href="http://uk.php.net/manual/en/function.usort.php">usort</a> and compare all elements with your function</p>
<p>Lambda functions are not replacement for __cal() and should be used cleverly, search and filtering with lambda functions is only one example of how useful they are. In short, lambda functions allows you to create small dynamic functions which can be used to expand and modify normal functions behaviour. </p>
]]></content:encoded>
			<wfw:commentRss>http://dev.juokaz.com/php/lambda-function-coming-to-php/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
