<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Cowburn</title>
	
	<link>http://cowburn.info</link>
	<description>Online storage depot for Peter Cowburn</description>
	<lastBuildDate>Sat, 17 Mar 2012 13:12:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/cowburn" /><feedburner:info uri="cowburn" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><meta xmlns="http://pipes.yahoo.com" name="pipes" content="noprocess" /><item>
		<title>Flattening a multidimensional array in PHP</title>
		<link>http://feedproxy.google.com/~r/cowburn/~3/uIHsDSv-2JM/</link>
		<comments>http://cowburn.info/2012/03/17/flattening-a-multidimensional-array-in-php/#comments</comments>
		<pubDate>Sat, 17 Mar 2012 13:11:29 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://cowburn.info/?p=487</guid>
		<description><![CDATA[This post is going to serve as a place to point people to, as it is a question that gets asked fairly regularly in the PHP support channels that I hang around in.  The task is to "flatten" nested arrays into a single series containing all of the values.]]></description>
				<content:encoded><![CDATA[<p>This post is going to serve as a place to point people to, as it is a question that gets asked fairly regularly in the PHP support channels that I hang around in.  The task is to &#8220;flatten&#8221; nested arrays into a single series containing all of the values.</p>
<h3>Example input array</h3>
<div class="codecolorer-container php twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$input</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'c'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'e'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'f'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'g'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h3>Expected output array</h3>
<div class="codecolorer-container php twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'c'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'d'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'e'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'f'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'g'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>It looks like most people usually resort to a function that calls itself recursively to build the output array.  My two examples below will give the expected output array, but will let PHP take care of the recursion for us.</p>
<h3>Iterator, Iterator, Iterator, Iterator</h3>
<p>This is my preferred way. OK, sure it creates a hierarchy of objects only to mush the values into an array, but it&#8217;s nice and concise. Besides, anyone who knows me knows I&#8217;m a fan of the <a href="http://php.net/spl" title="Standard PHP Library">SPL</a>.</p>
<div class="codecolorer-container php twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/iterator_to_array"><span style="color: #990000;">iterator_to_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> RecursiveIteratorIterator<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> RecursiveArrayIterator<span style="color: #009900;">&#40;</span><span style="color: #000088;">$input</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h3>Walking the array recursively</h3>
<p>This is a more procedural approach, but again it saves us from thinking about the recursion. It uses a <a href="http://php.net/closures">closure</a> to build up the array step by step.</p>
<div class="codecolorer-container php twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.php.net/array_walk_recursive"><span style="color: #990000;">array_walk_recursive</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$input</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;">$current</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">use</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$output</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$current</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h3>Resources</h3>
<ul>
<li><a href="http://php.net/recursivearrayiterator" title="RecursiveArrayIterator">RecursiveArrayIterator</a></li>
<li><a href="http://php.net/recursiveiteratoriterator" title="RecursiveIteratorIterator">RecursiveIteratorIterator</a></li>
<li><a href="http://php.net/iterator_to_array" title="iterator_to_array()">iterator_to_array()</a></li>
<li><a href="http://php.net/closures" title="Closures">Closures</a></li>
<li><a href="http://php.net/array_walk_recursive" title="array_walk_recursive()">array_walk_recursive()</a></li>
</ul>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cowburn?a=uIHsDSv-2JM:IA8nJXlrbIY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cowburn?i=uIHsDSv-2JM:IA8nJXlrbIY:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cowburn/~4/uIHsDSv-2JM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://cowburn.info/2012/03/17/flattening-a-multidimensional-array-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://cowburn.info/2012/03/17/flattening-a-multidimensional-array-in-php/</feedburner:origLink></item>
		<item>
		<title>Voting on PHP development processes</title>
		<link>http://feedproxy.google.com/~r/cowburn/~3/k8ReGUFT5-Q/</link>
		<comments>http://cowburn.info/2011/06/28/vote-php/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 22:15:32 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[internals]]></category>
		<category><![CDATA[RFC]]></category>
		<category><![CDATA[votes]]></category>

		<guid isPermaLink="false">http://cowburn.info/?p=462</guid>
		<description><![CDATA[This post is mostly going to be a (fairly) quick brain dump of my thoughts. Warning: they may not be particularly coherent or well explained. The topic of thought is my voting on two side-by-side votes centered on improving practices surrounding PHP version releases and additions to (or removals from) the language. For those with [...]]]></description>
				<content:encoded><![CDATA[<p>This post is mostly going to be a (fairly) quick brain dump of my thoughts. <strong>Warning:</strong> they may not be particularly coherent or well explained.  The topic of thought is my voting on two side-by-side votes centered on improving practices surrounding PHP version releases and additions to (or removals from) the language.<span id="more-462"></span></p>
<p>For those with some time to spare, the subjects were written up as RFCs for discussion on the <a href="http://news.php.net/php.internals">PHP internals mailing list</a> and were then put up for vote.  Those RFC pages are on the PHP wiki under <a href="https://wiki.php.net/rfc/voting">Voting on PHP features</a> (<a href="https://wiki.php.net/rfc/voting/votes">votes</a>) and <a href="https://wiki.php.net/rfc/releaseprocess">Release Process</a> (<a href="https://wiki.php.net/rfc/releaseprocess/votes">votes</a>).</p>
<p>Both votes are now closed and the tallies are as follows:</p>
<table>
<thead>
<tr>
<th>RFC</th>
<th>Yay</th>
<th>Nay</th>
</tr>
</thead>
<tbody>
<tr>
<td>Voting on PHP features</td>
<td>36</td>
<td>3</td>
</tr>
<tr>
<td>Release Process</td>
<td>26(+1)</td>
<td>5</td>
</tr>
</tbody>
</table>
<p>Now, on to the point of this post: I voted <strong>Nay</strong> to both of the RFCs.  As you will see (or not, if boredom sets in) neither are the strongest nay in the world but sitting on the fence would be a wasted opportunity.  </p>
<p><strong>Voting on PHP features</strong></p>
<p>It is beyond the scope of this post to detail what this RFC covers, go read it now. I&#8217;ll still be here when you&#8217;ve finished.  For those not wanting to bore themselves with the details, or as a reminder for whose who did, this particular topic boils down to: lets have more structured voting for changes to PHP, lets tag mailing list threads with [RFC] and [VOTE] as appropriate, lets move that voting off of the mailing list and on to the wiki, and finally lets put some minimum/guideline timeframes into place for the process.</p>
<p>All of the points are sensible and clearly are favourable to many over what we have (indeed, don&#8217;t have) at the moment.  But it all seems too lacking in substance and arbitrary for my taste.</p>
<p><em>Proposal initiation</em></p>
<p>Ideas for adoption by the community are mostly posted to internals for discussion anyway so the only real change on the discussion side of things is to make an RFC wiki page a mandatory feature.  However, requirements of and guidelines for RFC pages is completely glossed over (I&#8217;ll assume, because this is a <em>voting</em> RFC). Which proposals require an RFC, <em>every single one</em>? For minor changes, which for practical purposes an RFC might well be overkill, what place is there for a quick show of hands? Is that even to be considered/allowed at all?  What place is there for the &#8220;scratch an itch&#8221; changes that core developers love to slide in to PHP? (Aside: itch scratching is the main reason I got involved!)</p>
<p><em>Discussion period</em></p>
<p>The minimum amount of &#8220;thinking time&#8221; is stipulated as follows:</p>
<ul>
<li>1 week for RFCs that don&#8217;t &#8220;touch the language&#8221;</li>
<li>2 weeks for RFCs that do</li>
</ul>
<p>What exactly constitutes <em>touching</em> is not totally clear, but the example given in the next section is of adding new syntax (compared to, lets say, a new function or class).  Why those necessarily need double the amount of thinking time escapes me, as does why any RFC must require a minimum span of time between discussion on the mailing list (and elsewhere) and opening of the vote.  What <em>real</em> problems does this period solve? The numbers involved seem completely arbitrary and might as well have said 3 days, or 3 weeks.</p>
<p><em>Required Majority</em></p>
<p>Now, I&#8217;ll admit to having a love-hate relationship with this particular part of the RFC.  I love the idea of everyone having equal say from 15-year veteran of PHP to the brightest sparkly new face, to those who haven&#8217;t yet even ventured into the land of PHP internals discussions.  As an idea, it gives that warm, fuzzy feeling.</p>
<p>However, I also believe that we&#8217;re not all equal. My vote should <em>certainly not</em> carry the same weight as those who have many contributed orders of magnitude more to the language that I have or will, those who, in the past, may have vetoed proposals even with strong &#8220;yay&#8221; votes.  I like the idea of having people who can say, &#8220;no, that&#8217;s a crap idea and I won&#8217;t allow it.&#8221;  Of course everyone (everyone!) should be encouraged to give their own two pence, but if the likes of Rasmus, Zeev, Andi, or individual extension maintainers are dead against (or dead for) something then that has to mean more than, for example, my vote. Right? </p>
<p><em>Resurrecting Rejected Proposals</em></p>
<p>I don&#8217;t have much to say on this point. Giving previously rejected proposals another chance sounds fair enough to me, the wants and needs of <em>the community</em> does tend to sway over time. If a rejected proposal is improved enough to be &#8220;substantially&#8221; changed then it is likely not the same proposal at all so none of the old votes would be on the topic of the new, changed proposal anyway. </p>
<p><em>Who can vote</em></p>
<p>Everyone who uses PHP! Oh, no, wait, sorry that&#8217;s just impractical.  Everyone who has committed code to PHP! Oh, no, wait, sorry that&#8217;s just too few. Hmm, everyone who has written a framework! <em>*sideways glare*</em></p>
<p>I still have no idea of who we&#8217;re voting for being allowed to vote.  My conclusion is: whoever can be bothered signing up for a wiki account and following the required &#8220;hey, I&#8217;m not a robot&#8221; procedure.  </p>
<p><em>Conclusion</em></p>
<p>The aim of this RFC is to put in place a process to replace the old &#8220;+1&#8243; emails on the internals list.  That system had its problems, mostly in the shape of finding all of the votes to tally them! In the same way, I think that the proposed system also has problems which the RFC does not even attempt to provide direction or solutions, and also has solutions where there aren&#8217;t problems.</p>
<p><strong>Release Process</strong></p>
<p>As with the other RFC, I really do kind of agree with the sentiment of this proposal; it would be nice to have neat, tidy, regular releases (to <em>know</em> an addition will be publicly available within a year would be a nice incentive).  My main disagreement with this RFC is that we were expected to give a single yes/no vote on&#8230; well, multiple things.</p>
<p><em>Releases Cycle</em></p>
<p>I&#8217;m no expert on release cycles in open source projects, so comparison with what works elsewhere is beyond me.  The proposed yearly release cycle (for major versions) with 3-year lifetime seems super-duper short for PHP, as does a monthly (or less) cycle for minor releases, but if folks think it will work great then lets run with it.  I do worry however about having too many plates to keep spinning.  One of the illustrations shows 5 separate branches being actively developed concurrently.  I don&#8217;t know if that is a lot, or a drop in the ocean compared to other projects, but tackling just a couple of branches at any one time seems more than enough work for PHP at the moment.</p>
<p><em>Feature selection and development</em></p>
<p>There is not much to say for this section. The idea is that RFCs and wiki votes is the way forward.  However it does add to the list of questions that we&#8217;re supposed to provide a single vote for/against. The topic of who can vote should have been decided during discussion (and a previous vote!), and the proposal updated to reflect that.  We can&#8217;t say &#8220;yes&#8221; to, &#8220;<em>Who will be allowed to vote?</em>&#8221;</p>
<p><em>RMs Role</em></p>
<p>Apparently, they won&#8217;t be allowed to decided which non-bug-fix changes get to go into a release.  So much for, &#8220;hey, that&#8217;s still super-buggy lets keep working on it for a while.&#8221;  I believe a release manager should have the final say as to whether any individual feature is ready to go into a release. The RFC doesn&#8217;t make this clear, but it certainly sounds like once something has been committed, it <em>will</em> be in the next release; at least, there is no mention of anyone (community decision or otherwise) agreeing whether a feature is ready or not.</p>
<p><em>Release managers selection</em></p>
<p>The idea here is that pairs should put themselves forward as RMs, and we should vote them in.  Are there really so many pushing to become RMs?  I have not been around the core for too long but I&#8217;ve certainly not seen an over-abundance of volunteers for the role.  This particular proposal sounds like needless <a href="http://en.wiktionary.org/wiki/faff">faff</a>.</p>
<p><em>Feature(s) preview release, solving the experimental features</em></p>
<p>Harking back to an earlier section, the aim here is to provide &#8220;feature preview&#8221; releases so that new features can get some more thorough real-life testing/use by brave folks before hitting a normal release.  As with above, there is no scope for &#8220;whoa, this really isn&#8217;t ready yet&#8221; or even &#8220;what were we thinking?!&#8221; whatsoever. On the plus side, more testing is a <em>very good thing</em>.</p>
<p><em>Security Management</em></p>
<p>This section gets a big thumbs up from me, even though not being able to read the security-related bugs is a personal annoyance.  How this relates to the rest of the RFC in any way is questionable, but I like it.</p>
<p><em>Conclusion</em></p>
<p>As with the other RFC, the general theme is certainly something I will support.  However, the devil is in the details and in this case so is my disagreement with what is, and isn&#8217;t, being put on the table here. </p>
<p><strong>And finally</strong></p>
<p>The primary reason for this post is not to start some long-winded discussion on the above, merely to document my varied thoughts.  If any discussion does come of it, then that&#8217;s great but I will probably run away and hide if people start getting all outspoken. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cowburn?a=k8ReGUFT5-Q:Wi0HjNWyCRw:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cowburn?i=k8ReGUFT5-Q:Wi0HjNWyCRw:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cowburn/~4/k8ReGUFT5-Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://cowburn.info/2011/06/28/vote-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://cowburn.info/2011/06/28/vote-php/</feedburner:origLink></item>
		<item>
		<title>PHP 5.3.4 Released</title>
		<link>http://feedproxy.google.com/~r/cowburn/~3/tqTpyXJ-auI/</link>
		<comments>http://cowburn.info/2010/12/10/php-5-3-4-released/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 07:50:16 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://cowburn.info/?p=452</guid>
		<description><![CDATA[Today, version 4 in the PHP 5.3 branch has been packaged and made available to everyone. As usual it contains security fixes, over a hundred bug fixes and feature requests, and lots of other additions &#038; improvements. Some highlights (my own choice) are below: Favourite changes Paths containing NULL (like /some/path\0foo.txt ) are now considered [...]]]></description>
				<content:encoded><![CDATA[<p>Today, version 4 in the PHP 5.3 branch has been packaged and made available to everyone. As usual it contains security fixes, over a hundred bug fixes and feature requests, and lots of other additions &#038; improvements. Some highlights (my own choice) are below:</p>
<p><strong>Favourite changes</strong></p>
<ul>
<li>Paths containing<br />
<samp>NULL</samp>
<p> (like<br />
<samp>/some/path\0foo.txt</samp>
<p>) are now considered invalid.</li>
<li>Added <var>follow_location</var> (enabled by default) option for the http stream support.</li>
<li>Implemented FR #50692, not uploaded files don&#8217;t count towards <var>max_file_uploads</var> limit. As a side improvement, temporary files are not opened for empty uploads and, in debug mode, 0-length uploads.</li>
<li>Fixed bug #53409 (<code>sleep()</code> returns<br />
<samp>NULL</samp>
<p> on Windows).</li>
<li>Fixed covariance of return-by-ref constraints.</li>
<li>Fixed bug #50579 (<code>RegexIterator::REPLACE</code> doesn&#8217;t work).</li>
<li>Upgraded bundled PCRE to version 8.10.</li>
<li>Upgraded bundled Sqlite3 to version 3.7.3.</li>
</ul>
<p>Also, 5.2.15 was released yesterday, which marks the end of support for PHP 5.2. <img src='http://cowburn.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>For full information see the <a href="http://www.php.net/archive/2010.php#id2010-12-10-1">5.3.4</a> and <a href="http://www.php.net/archive/2010.php#id2010-12-09-1">5.2.15</a> announcements on php.net.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cowburn?a=tqTpyXJ-auI:ZSuz0m7Mv3A:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cowburn?i=tqTpyXJ-auI:ZSuz0m7Mv3A:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cowburn/~4/tqTpyXJ-auI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://cowburn.info/2010/12/10/php-5-3-4-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://cowburn.info/2010/12/10/php-5-3-4-released/</feedburner:origLink></item>
		<item>
		<title>PHP 5.3.3 released!</title>
		<link>http://feedproxy.google.com/~r/cowburn/~3/8veSQFx0NxM/</link>
		<comments>http://cowburn.info/2010/07/22/php-5-3-3-released/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 10:47:14 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php.net]]></category>
		<category><![CDATA[php5.3.3]]></category>

		<guid isPermaLink="false">http://cowburn.info/?p=440</guid>
		<description><![CDATA[Today, the latest version of PHP 5.3 (as well as the latest in the 5.2 branch, 5.2.14) has been released to the masses. The official announcement can found in the news archive with finer details in the changelog. A select few of the changes, of particular interest to me, are outlined below. Added support for [...]]]></description>
				<content:encoded><![CDATA[<p>Today, the latest version of PHP 5.3 (as well as the latest in the 5.2 branch, 5.2.14) has been released to the masses. The official announcement can found in the <a href="http://www.php.net/archive/2010.php#id2010-07-22-2" title="PHP: News Archive - 2010">news archive</a> with finer details in the <a href="http://www.php.net/ChangeLog-5.php#5.3.3" title="PHP 5.3.3 Changelog">changelog</a>.  A select few of the changes, of particular interest to me, are outlined below.<span id="more-440"></span></p>
<blockquote cite="http://www.php.net/ChangeLog-5.php#5.3.3">
<ul>
<li>Added support for copy to/from array/file for pdo_pgsql extension. (Denis Gasparin, Ilia)</li>
<li>Changed namespaced classes so that the ctor can only be named __construct now. (Stas)</li>
<li>Fixed bug #51590 (JSON_ERROR_UTF8 is undefined). (Felipe)</li>
<li>Fixed bug #49576 (FILTER_VALIDATE_EMAIL filter needs updating) (Rasmus)</li>
<li>Fixed bug #48361 (SplFileInfo::getPathInfo should return the parent dir). (Etienne)</li>
<li>And well over a hundred other bug and security fixes</li>
</ul>
</blockquote>
<p>The change to constructors in namespaced classes has already been the subject of &#8220;why doesn&#8217;t this work&#8221; questions. With 5.3.3 you <em>cannot</em> define class constructors like below.</p>
<div class="codecolorer-container text twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;code lang=&quot;php&quot;&gt;<br />
namespace Foo {<br />
&nbsp; &nbsp; class Bar {<br />
&nbsp; &nbsp; &nbsp; &nbsp; function Bar() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // constructing \Foo\Bar class<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
}<br />
&lt;/code&gt;</div></div>
<p>Instead, you need to be using the right and proper <code lang="php">__construct</code> method. Note that this only applies to namespaced classes, so old code can continue (if they like) using the class-name-based constructor. This really only affects the (few?) folks who might be making use of, or adapting their old code to use, namespaces yet still keeping the old style of naming the constructor method.</p>
<p>Go, play!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cowburn?a=8veSQFx0NxM:FOhIN46HdjY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cowburn?i=8veSQFx0NxM:FOhIN46HdjY:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cowburn/~4/8veSQFx0NxM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://cowburn.info/2010/07/22/php-5-3-3-released/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://cowburn.info/2010/07/22/php-5-3-3-released/</feedburner:origLink></item>
		<item>
		<title>Happy 15th, PHP</title>
		<link>http://feedproxy.google.com/~r/cowburn/~3/Cs_-f5_GIk0/</link>
		<comments>http://cowburn.info/2010/06/08/happy-15th-php/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 07:58:57 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[birthday]]></category>
		<category><![CDATA[php.net]]></category>

		<guid isPermaLink="false">http://cowburn.info/?p=429</guid>
		<description><![CDATA[Today marks the 15th birthday* of PHP. I did have a nice, long post planned but lost it during the drafting process (maybe I should use WordPress which auto-saves?). So, in a new concise train of thought I&#8217;ll leave the rambling to other folks in the PHP community who will (hopefully) be providing their reflections [...]]]></description>
				<content:encoded><![CDATA[<p>Today marks the 15th birthday<a href="#fn1">*</a> of PHP. I did have a nice, long post planned but lost it during the drafting process (maybe I should use WordPress which auto-saves?).  So, in a new concise train of thought I&#8217;ll leave the rambling to other folks in the PHP community who will (hopefully) be providing their reflections over the last decade and a half. I&#8217;ll amend links to this post for those who don&#8217;t want to search around for birthday wishes.</p>
<p>Happy birthday, PHP! <img src='http://cowburn.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <span id="more-429"></span></p>
<p class="aside" id="fn1">* See <a href="http://groups.google.com/group/comp.infosystems.www.authoring.cgi/browse_thread/thread/3f2276e6067acfb0/cc7d43454d64d133" title="Announce: Personal Home Page Tools (PHP Tools) Options">Announce: Personal Home Page Tools (PHP Tools) Options</a> (8th June 1995)</p>
<h3>Elsewhere</h3>
<ul>
<li><a href="http://schlueters.de/blog/archives/136-15-years-of-PHP.html" title="15 years of PHP">15 years of PHP</a> from Johannes Schlüter</li>
</ul>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cowburn?a=Cs_-f5_GIk0:UBkbYBbjmAI:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cowburn?i=Cs_-f5_GIk0:UBkbYBbjmAI:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cowburn/~4/Cs_-f5_GIk0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://cowburn.info/2010/06/08/happy-15th-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://cowburn.info/2010/06/08/happy-15th-php/</feedburner:origLink></item>
		<item>
		<title>Glob Patterns for File Matching in PHP</title>
		<link>http://feedproxy.google.com/~r/cowburn/~3/8wFCszIwzU0/</link>
		<comments>http://cowburn.info/2010/04/30/glob-patterns/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 18:16:46 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[glob]]></category>
		<category><![CDATA[spl]]></category>

		<guid isPermaLink="false">http://cowburn.info/?p=390</guid>
		<description><![CDATA[This article has been on the cards for a while now with recent articles elsewhere1,2 prompting me to get this finished and up on the blog. The focus here is on the wildcard patterns that can be used with glob. Intro to the glob function To quote the succinct description on the PHP manual page [...]]]></description>
				<content:encoded><![CDATA[<p>This article has been on the cards for a while now with recent articles elsewhere<sup><a href="#fn1" title="php|architect - Putting glob() to the test">1</a>,<a href="#fn2" title="Nettuts+ - Loop Through Folders with PHP’s Glob()">2</a></sup> prompting me to get this finished and up on the blog. The focus here is on the wildcard patterns that can be used with <code>glob</code>.<span id="more-390"></span>  </p>
<h3>Intro to the <code>glob</code> function</h3>
<p>To quote the succinct description on the <a href="http://php.net/glob" title="PHP: Glob">PHP manual page</a> for <code>glob</code>:</p>
<blockquote cite="http://php.net/glob" datetime="2010-04-30T16:20:00Z"><p>The <code>glob()</code> function searches for all the pathnames matching <var>pattern</var> according to the rules used by the libc <code>glob()</code> function, which is similar to the rules used by common shells.<br />
<cite>http://php.net/glob</cite></p></blockquote>
<h3>What&#8217;s in a pattern?</h3>
<p>Most people who have already encountered <code>glob</code> know to make use of the <code>*</code> metacharacter to match <em>some characters</em>, and those digging a little deeper often discover that discrete alternatives can be globbed with braces (e.g. <code>image.{gif,jpg,png}</code>). However, there are more special characters and sequences that can be used to be more (or less, if we want) specific about what to find. </p>
<p class="small"><em>Aside</em>: please <strong>do not</strong> make the mistake of thinking that glob patterns are <em>regular expressions</em>, they&#8217;re just not. If you do want to use regular expressions to find paths/files then you are invited to use SPL&#8217;s <a href="http://php.net/regexiterator" title="PHP: SPL RegexIterator">RegexIterator</a>, which allows filtering of an Iterator based on a PCRE regex, in conjunction with a DirectoryIterator or FilesystemIterator (there are recursive flavours of the Regex- and DirectoryIterator if you need to delve into folders). For those SPL-ly inclined, also note the <a href="http://php.net/globiterator" title="PHP: SPL GlobIterator">GlobIterator</a> which combines the goodness of globbing with iteration. If that made entirely <em>no sense</em>, please read on! Globs are much less verbose…</p>
<p>So, here are the special doohickeys (technical term!) that we can use with <code>glob</code>:</p>
<dl>
<dt><code>*</code> (an asterisk)</dt>
<dd>Matches zero of more characters.</dd>
<dt><code>?</code></dt>
<dd>Matches exactly any one character.</dd>
<dt><code>[...]</code></dt>
<dd>Matches one character from a group.  A group can be a list of characters, e.g. <code>[afkp]</code>, or a range of characters, e.g. <code>[a-g]</code> which is the same as <code>[abcdefg]</code>.</dd>
<dt><code>[!...]</code></dt>
<dd>Matches any single character not in the group. <code>[!a-zA-Z0-9]</code> matches any character that is not alphanumeric.</dd>
<dt><code>\</code></dt>
<dd>Escapes the next character. For special characters, this causes them to not be treated as special. For example, <code>\[</code> matches a literal<br />
<samp>[</samp>
<p>. If <var>flags</var> includes <var>GLOB_NOESCAPE</var>, this quoting is disabled and <code>\</code> is handled as a simple character. </dd>
</dl>
<h3>Globbingly good glob examples</h3>
<p>Here are a few examples of what globs might look like alongside a brief description of the intended behaviour: if you have any suggestions please do make them in the comments as I'm running short on inspiration! </p>
<table class="light">
<thead>
<tr style="width:20%">
<th>pattern</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>*.txt</code></td>
<td>Get directory contents which have the extension of<br />
<samp>.txt</samp>
<p> (Note: a file could be named simply<br />
<samp>.txt</samp>
<p>!).</td>
</tr>
<tr>
<td><code>??</code></td>
<td>Get directory contents with names <em>exactly</em> two characters in length.</td>
</tr>
<tr>
<td><code>??*</code></td>
<td>Get directory contents with names <em>at least</em> two characters in length.</td>
</tr>
<tr>
<td><code>g?*</code></td>
<td>Get directory contents with names at least two characters in length and starting with the letter<br />
<samp>g</samp>
</td>
</tr>
<tr>
<td><code>*.{jpg,gif,png}</code></td>
<td>Get directory contents with an extension of<br />
<samp>.jpg</samp>
<p>,<br />
<samp>.gif</samp>
<p> or<br />
<samp>.png</samp>
<p>. Remember to use the <var>GLOB_BRACE</var> flag.</td>
</tr>
<tr>
<td><code>DN?????.dat</code></td>
<td>Get directory contents which start with the letters<br />
<samp>DN</samp>
<p>, followed by five characters, with an extension of<br />
<samp>.dat</samp>
<p>.</td>
</tr>
<tr>
<td><code>DN[0-9][0-9][0-9][0-9][0-9].dat</code></td>
<td>Get directory contents which start with the letters<br />
<samp>DN</samp>
<p>, followed by five <em>digits</em>, with an extension of<br />
<samp>.dat</samp>
<p>.</td>
</tr>
<tr>
<td><code>[!aeiou]*</code></td>
<td>Get directory contents which do not start with a vowel letter.</td>
</tr>
<tr>
<td><code>[!a-d]*</code></td>
<td>Get directory contents which do not start with<br />
<samp>a</samp>
<p>,<br />
<samp>b</samp>
<p>,<br />
<samp>c</samp>
<p> or<br />
<samp>d</samp>
<p>.</td>
</tr>
<tr>
<td><code>*\[[0-9]\].*</code></td>
<td>Get directory contents whose basename ends with a single digit enclosed in square braces. If <var>GLOB_NOESCAPE</var> is used, a single digit enclosed in<br />
<samp>\[</samp>
<p> and<br />
<samp>\]</samp>
<p> which would be a pretty weird name.</td>
</tr>
<tr>
<td><code>subdir/img*/th_?*</code></td>
<td>Get directory contents whose name starts with<br />
<samp>th_</samp>
<p> (with at least one character after that) within directories whose names start with<br />
<samp>img</samp>
<p> in the<br />
<samp>subdir</samp>
<p> directory.</td>
</tr>
</tbody>
</table>
<p>Well there we go, I&#8217;ve said what I came here to say so all that remains to be done is give some link love to those  two recent articles that prompted me to dust off this draft and click the &#8220;publish&#8221; button. </p>
<h6>With thanks</h6>
<ol>
<li id="fn1">php|architect&#8217;s <a href="http://www.phparch.com/2010/04/28/putting-glob-to-the-test/" title="Putting glob() to the test">Putting glob() to the test</a> focuses on execution times of <code>glob</code> and other techniques of getting a list of files.</li>
<li id="fn2">Marcus Schumann&#8217;s <a href="http://net.tutsplus.com/tutorials/php/quick-tip-loop-through-folders-with-phps-glob/" title="Loop Through Folders with PHP’s Glob()">Loop Through Folders with PHP’s Glob()</a> article on Nettuts+ gives a brief introduction for those who might not have been introduced to <code>glob</code>.</li>
</ol>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cowburn?a=8wFCszIwzU0:-pBDMfJ4uHw:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cowburn?i=8wFCszIwzU0:-pBDMfJ4uHw:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cowburn/~4/8wFCszIwzU0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://cowburn.info/2010/04/30/glob-patterns/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://cowburn.info/2010/04/30/glob-patterns/</feedburner:origLink></item>
		<item>
		<title>PHP 5.3.2 Released</title>
		<link>http://feedproxy.google.com/~r/cowburn/~3/CGc6MlGtpi0/</link>
		<comments>http://cowburn.info/2010/03/04/php-5-3-2-released/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 21:51:49 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Random Thoughts]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php.net]]></category>
		<category><![CDATA[php5.3.2]]></category>

		<guid isPermaLink="false">http://cowburn.info/?p=387</guid>
		<description><![CDATA[Today, the latest version of PHP 5.3 has been released to the masses. The official announcement can found in the news archive with finer details in the changelog. Key points were outlined in the announcement, partially quoted below.]]></description>
				<content:encoded><![CDATA[<p>Today, the latest version of PHP 5.3 has been released to the masses. The official announcement can found in the <a href="http://www.php.net/archive/2010.php#id2010-03-04-1" title="PHP: News Archive - 2010">news archive</a> with finer details in the <a href="http://www.php.net/ChangeLog-5.php#5.3.2" title="PHP 5.3.2 Changelog">changelog</a>.  Key points were outlined in the announcement, partially quoted below.<span id="more-387"></span></p>
<blockquote cite=""http://www.php.net/archive/2010.php#id2010-03-04-1">
<h4>Security Enhancements and Fixes in PHP 5.3.2:</h4>
<ul>
<li>Improved LCG entropy. (Rasmus, Samy Kamkar)</li>
<li>Fixed safe_mode validation inside tempnam() when the directory path does not end with a /). (Martin Jansen)</li>
<li>Fixed a possible open_basedir/safe_mode bypass in the session extension identified by Grzegorz Stachowiak. (Ilia)</li>
</ul>
<h4>Key Bug Fixes in PHP 5.3.2 include:</h4>
<ul>
<li>Added support for SHA-256 and SHA-512 to php&#8217;s crypt.</li>
<li>Added protection for $_SESSION from interrupt corruption and improved &#8220;session.save_path&#8221; check.</li>
<li>Fixed bug #51059 (crypt crashes when invalid salt are given).</li>
<li>Fixed bug #50940 Custom content-length set incorrectly in Apache sapis.</li>
<li>Fixed bug #50847 (strip_tags() removes all tags greater then 1023 bytes long).</li>
<li>Fixed bug #50723 (Bug in garbage collector causes crash).</li>
<li>Fixed bug #50661 (DOMDocument::loadXML does not allow UTF-16).</li>
<li>Fixed bug #50632 (filter_input() does not return default value if the variable does not exist).</li>
<li>Fixed bug #50540 (Crash while running ldap_next_reference test cases).</li>
<li>Fixed bug #49851 (http wrapper breaks on 1024 char long headers).</li>
<li>Over 60 other bug fixes.</li>
</ul>
</blockquote>
<p>Other nice improvements with this version include an (almost) up-to-date <a href="http://pcre.org" title="PCRE - Perl Compatible Regular Expressions">PCRE</a> library (PHP 5.3.2 includes PCRE 8.00 with the latest version being 8.01) for regular expressions and a number of nice improvements to the <a href="http://php.net/filter" title="PHP: Filter - Manual">filter extension</a> both of which I use very regularly.  </p>
<p>Do you, dear reader, keep up-to-date with PHP 5.3 (or 5.2) or are you stuck with steadily aging versions due to restrictive hosting providers?</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cowburn?a=CGc6MlGtpi0:EO66ShuAClU:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cowburn?i=CGc6MlGtpi0:EO66ShuAClU:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cowburn/~4/CGc6MlGtpi0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://cowburn.info/2010/03/04/php-5-3-2-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://cowburn.info/2010/03/04/php-5-3-2-released/</feedburner:origLink></item>
		<item>
		<title>Using PHP Functions in XPath Expressions</title>
		<link>http://feedproxy.google.com/~r/cowburn/~3/WojNZ1aU-30/</link>
		<comments>http://cowburn.info/2009/10/23/php-funcs-xpath/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 20:41:13 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[XPath]]></category>
		<category><![CDATA[DOM]]></category>

		<guid isPermaLink="false">http://cowburn.info/?p=336</guid>
		<description><![CDATA[Disclaimer: this article expects familiarity with using the DOM1 extension and XPath2 expressions. The (currently undocumentednow documented3) DOMXPath::registerPHPFunctions method is available as of PHP 5.3.0 (it was added to the code base back in December 2006) and allows the use of PHP functions (and static methods) within XPath queries to complement the normal set of [...]]]></description>
				<content:encoded><![CDATA[<p>Disclaimer: this article expects familiarity with using the DOM<sup><a href="#fn1" title="footnote 1">1</a></sup> extension and XPath<sup><a href="#fn2" title="footnote 2">2</a></sup> expressions. </p>
<p>The (<del datetime="2009-10-26T14:15:44Z">currently undocumented</del><ins datetime="2009-10-26T14:15:44Z">now documented</ins><sup><a href="#fn3" title="footnote 3">3</a></sup>) <code>DOMXPath::registerPHPFunctions</code> method is available as of PHP 5.3.0 (it was added to the code base back in December 2006) and allows the use of PHP functions (and static methods) within XPath queries to complement the normal set of XPath functions<sup><a href="#fn2" title="footnote 2">2</a></sup>.<span id="more-336"></span></p>
<h3>Description</h3>
<p><code>void <strong>DOMXPath::registerPHPFunctions</strong>  ([ string|array <var>$restrict</var>] )</code></p>
<p>Enables the use of PHP functions as XPath functions.</p>
<h3>Parameters</h3>
<dl>
<dt>restrict</dt>
<dd>
Use this parameter to only allow certain functions to be called from XPath; it can be either a string (a function name) or an array of function names.
</dd>
</dl>
<h3>Return Values</h3>
<p>No value is returned.</p>
<h3>Examples</h3>
<p><strong>Note:</strong> The following examples load a sample XML document called <kbd>book.xml</kbd> with the following contents:</p>
<div class="codecolorer-container xml twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;books<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>PHP Basics<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Jim Smith<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Jane Smith<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>PHP Secrets<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Jenny Smythe<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>XML basics<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Joe Black<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/books<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<h3 id="ex1">Example #1: Call a PHP function in XPath with <code>php:functionString</code></h3>
<p>This example demonstrates the basic use of <code>DOMXPath::registerPHPFunctions</code> by replicating the <code>substring</code> XPath function. The first thing that needs to be done is to register the<br />
<samp>php</samp>
<p> namespace with the associated URI<br />
<samp>http://php.net/xpath</samp>
<p>. Don&#8217;t question it, it just needs to be done!</p>
<p>Next, we call <code>DOMXPath::registerPHPFunctions</code> on our object. If no arguments are used, as in this example, then the range of functions allowed to be called is not restricted—you can call any<sup><a href="#fn4" title="footnote 4">4</a></sup> function from XPath. I would always advise restricting the functions which can be called, see <a href="#ex2" title="Example 2">example 2</a>.</p>
<p>Within our XPath query, we use <code>php:functionString</code> which allows us to name a function and provide some parameters (or indeed, no parameters) to be passed to that function. There are two flavours which can be used here: <code>php:functionString</code> which passes an XML node/attribute as a string and <code>php:function</code> (see <a href="#ex3" title="Example 3">example 3</a>) which passes an array of XML node/attribute objects (in <code>DOMElement</code> / <code>DOMAttr</code> / etc. form) to the function .  In this example the PHP function <a href="http://php.net/substr"><code>substr</code></a> is called, passing along the book&#8217;s title (in string form), an offset of<br />
<samp>0</samp>
<p> and length of<br />
<samp>3</samp>
<p>. This returns the first 3 characters of the book&#8217;s title which is then compared to the string <kbd>PHP</kbd> in order to filter our list of books down to those having titles starting with <kbd>PHP</kbd>.</p>
<div class="codecolorer-container php twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000088;">$dom</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'book.xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$xpath</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMXPath<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dom</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Register the php: namespace (required)</span><br />
<span style="color: #000088;">$xpath</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerNamespace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;php&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;http://php.net/xpath&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Register PHP functions (no restrictions)</span><br />
<span style="color: #000088;">$xpath</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerPHPFunctions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Call substr function on the book title</span><br />
<span style="color: #000088;">$nodes</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xpath</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'//book[php:functionString(&quot;substr&quot;, title, 0, 3) = &quot;PHP&quot;]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Found <span style="color: #006699; font-weight: bold;">{$nodes-&gt;length}</span> books starting with 'PHP':<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$nodes</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$title</span> &nbsp;<span style="color: #339933;">=</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$author</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;author&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$title</span> by <span style="color: #006699; font-weight: bold;">$author</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>The example will output something like:</p>
<div class="codecolorer-container plain twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="plain codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Found 2 books starting with 'PHP':<br />
PHP Basics by Jim Smith<br />
PHP Secrets by Jenny Smythe</div></div>
<h3 id="ex2">Example #2: Restricting the functions available to XPath</h3>
<p>To restrict the functions made available to XPath, provide either a string containing the name of the single function that you wish to allow or an array of strings containing function names as the <var>restrict</var> parameter (note: static methods can also be used, e.g. &#8220;<br />
<samp>Classname::method</samp>
<p>&#8220;).  If functions were added with <var>restrict</var> and a function is called in XPath which is not one of them, an <var>E_WARNING</var> will be raised stating<br />
<samp>Not allowed to call handler &#8216;<var>function</var>()&#8217;</samp>
<p> (where <var>function</var> is the name of the function that cannot be called).</p>
<div class="codecolorer-container php twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000088;">$dom</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'book.xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$xpath</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMXPath<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dom</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Register the php: namespace (required)</span><br />
<span style="color: #000088;">$xpath</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerNamespace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;php&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;http://php.net/xpath&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Register PHP functions (no restrictions)</span><br />
<span style="color: #000088;">$xpath</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerPHPFunctions</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;strtoupper&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Get first book's title in uppercase</span><br />
<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xpath</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">evaluate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'php:functionString(&quot;strtoupper&quot;, //book[1]/title)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$title</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Try a function not in our restrictions list</span><br />
<span style="color: #000088;">$fail</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xpath</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">evaluate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'php:functionString(&quot;strtolower&quot;, //book[1]/title)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>The example will output something like:</p>
<div class="codecolorer-container plain twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="plain codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PHP BASICS&lt;br /&gt;<br />
&lt;b&gt;Warning&lt;/b&gt;: &nbsp;DOMXPath::evaluate() [&lt;a href='domxpath.evaluate'&gt;domxpath.evaluate&lt;/a&gt;]: Not allowed to call handler 'strtolower()'. in &lt;b&gt;example2.php&lt;/b&gt; on line &lt;b&gt;18&lt;/b&gt;&lt;br /&gt;</div></div>
<h3 id="ex3">Example #3: Passing DOM objects using <code>php:function</code></h3>
<p>Up to now, the examples have both used <code>php:functionString</code>. As mentioned above, instead of passing a string value to the PHP function it is possible to pass along an array of DOM* objects to manipulate them as you please by using <code>php:function</code>.</p>
<div class="codecolorer-container php twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000088;">$dom</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'book.xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$xpath</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMXPath<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dom</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Register the php: namespace (required)</span><br />
<span style="color: #000088;">$xpath</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerNamespace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;php&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;http://php.net/xpath&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Register PHP functions (no restrictions)</span><br />
<span style="color: #000088;">$xpath</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerPHPFunctions</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;example3&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> example3<span style="color: #009900;">&#40;</span><span style="color: #000088;">$nodes</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Return true if more than one author</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nodes</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #666666; font-style: italic;">// Filter books with multiple authors</span><br />
<span style="color: #000088;">$books</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xpath</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'//book[php:function(&quot;example3&quot;, author)]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Books with multiple authors:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$books</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$book</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>The example will output something like:</p>
<div class="codecolorer-container plain twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="plain codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Books with multiple authors:<br />
PHP Basics</div></div>
<h3>Summary</h3>
<p>Just to quickly summarise everything, here is a quick run-down. In PHP, make sure to register the <kbd>php</kbd> namespace (with the URI <kbd>http://php.net/xpath</kbd>) and then register your PHP functions (whether core, extensions or user-defined) or static methods with <code>DOMXPath::registerPHPFunctions</code>. In XPath, use <code>php:functionString</code> or <code>php:function</code> to call the PHP function.</p>
<p>If you have made use of this feature, or want to know more, then do feel free to comment. Thanks for reading.</p>
<h4>Footnotes</h4>
<ol>
<li id="fn1"><a href="http://php.net/dom" title="PHP: DOM">http://php.net/dom</a></li>
<li id="fn2"><a href="http://schlitt.info/opensource/blog/0704_xpath.html" title="XPath overview">http://schlitt.info/opensource/blog/0704_xpath.html</a>
<li id="fn3">The documentation page, <del datetime="2009-10-26T14:15:44Z">when it gets written, will be</del><ins datetime="2009-10-26T14:15:44Z">is</ins> available at <a href="http://php.net/domxpath.registerphpfunctions" title="PHP: DOMXPath::registerPHPFunctions">http://php.net/domxpath.registerphpfunctions</a></li>
<li id="fn4">In truth, some functions are not suitable such as those that return non-scalar values (and cannot be cast to one) which XPath will not understand.</li>
</ol>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cowburn?a=WojNZ1aU-30:kBhcs3F55rk:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cowburn?i=WojNZ1aU-30:kBhcs3F55rk:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cowburn/~4/WojNZ1aU-30" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://cowburn.info/2009/10/23/php-funcs-xpath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://cowburn.info/2009/10/23/php-funcs-xpath/</feedburner:origLink></item>
		<item>
		<title>Comments on “Creating a Crypter Class with PHP”</title>
		<link>http://feedproxy.google.com/~r/cowburn/~3/xd9KlHW5JX4/</link>
		<comments>http://cowburn.info/2009/09/28/nettuts-crypter/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 20:22:02 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Random Thoughts]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[crypter]]></category>
		<category><![CDATA[nettuts]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://cowburn.info/?p=326</guid>
		<description><![CDATA[The following was supposed to be a comment to the Nettuts+ article published recently entitled Creating a Crypter Class with PHP. The powers that be over there seem not to want to moderate the comment so I&#8217;ll publish it here and hopefully the trackback will connect things together. The comment is after the fold and [...]]]></description>
				<content:encoded><![CDATA[<p>The following was supposed to be a comment to the <a href="http://net.tutsplus.com" title="Web Development &#038; Design Tutorials - Nettuts+">Nettuts+</a> article published recently entitled <a href="http://net.tutsplus.com/tutorials/php/creating-a-crypter-class/" title="Read 'Creating a Crypter Class with PHP'">Creating a Crypter Class with PHP</a>.  The powers that be over there seem not to want to moderate the comment so I&#8217;ll publish it here and hopefully the trackback will connect things together. The comment is after the fold and it would make sense to perhaps at least scan over <a href="http://net.tutsplus.com/tutorials/php/creating-a-crypter-class/" title="Read 'Creating a Crypter Class with PHP'">Christian&#8217;s article</a> before reading my comments.<span id="more-326"></span></p>
<h3>Original Comment (#112314)</h3>
<blockquote cite="http://net.tutsplus.com/tutorials/php/creating-a-crypter-class/#comment-112314"><p>
Hi Christian, thank you for the article. I would like to share a few comments if I may.</p>
<p>You seem to create the interface (ICrypter) almost without considering why an interface might be necessary. The article skirts around the reasons why an interface might be handy, instead preferring to mention that any class which implements a given interface must adhere to it (other than, “there will be an error!”). It is far outside the realm of a simple blog comment to delve into this subject so I can only suggest that readers take it upon themselves to build their own understanding of interfaces in general and in PHP. There is a lot of great information out there (for a recent insight into the subject, see <a href="http://www.brandonsavage.net/why-interfaces-rock/" title="Why Interfaces Rock | BrandonSavage.net">http://www.brandonsavage.net/why-interfaces-rock/</a> ).</p>
<p>The article doesn’t state anywhere (though it will be mightily obvious when a reader tries to use the code) that MCrypt is required. Readers, see <a href="http://php.net/mcrypt.requirements" title="PHP: MCrypt Requirements">http://php.net/mcrypt.requirements</a> and <a href="http://mcrypt.sourceforge.net/" title="MCrypt">http://mcrypt.sourceforge.net/</a></p>
<p>With regards to the list of “supported algorithms from php.net” it would have been nice to have a source cited for reference. See <a href="http://php.net/mcrypt.ciphers" title="PHP: MCrypt Ciphers">http://php.net/mcrypt.ciphers</a></p>
<p>The remarks about Base64 encoding/decoding values seems a little odd. Why would you automatically want to do this? Your argument is that the encrypted value might not be URL-safe but that is only an issue if the encrypted value is being placed in an URL. If you do need to use the encrypted value in an URL then it would make more sent to encode the value only when it needs to be. Base64 is not the only available option for making such a value URL-safe (the functions urlencode and http_build_query to name a few).</p>
<p>It also puzzles me that you use the trim function on the Base64-encoded value since there will not be any whitespace present to be trimmed! The same goes for trimming the decrypted value since there may be important whitespace which really should not be trimmed. </p>
<p>The article itself does not elude to why this helper class might be useful. Your comments state there will be a follow-up article with a more practical demonstration but sure it would have been nice to include a very brief situation and code example where this type of encryption/decryption is of particular benefit.</p>
<p>I guess that is enough writing for a blog comment! Congratulations on publishing your first article on Nettuts+ and I look forward to your next ones.</p></blockquote>
<p>The above is my comment, copied verbatim (with the links manually added since WordPress didn&#8217;t want to do that). Someone probably just missed by comment in the queue, so whether it appears on the Nettuts+ site or not remains to be seen. Either way the full comment is available here for reference.</p>
<p class="small" datetime="2009-09-28T21:45:12Z">Edit: between publishing this (at 8:22pm) and now (10:45pm) the comment got approved and is up on the Nettuts+ website. Guess I was just slightly too quick out of the blocks in republishing it here.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cowburn?a=xd9KlHW5JX4:uZ4w9Rp3W9E:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cowburn?i=xd9KlHW5JX4:uZ4w9Rp3W9E:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cowburn/~4/xd9KlHW5JX4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://cowburn.info/2009/09/28/nettuts-crypter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://cowburn.info/2009/09/28/nettuts-crypter/</feedburner:origLink></item>
		<item>
		<title>The InfiniteIterator in PHP</title>
		<link>http://feedproxy.google.com/~r/cowburn/~3/IXtnrxwCnu8/</link>
		<comments>http://cowburn.info/2009/09/25/infiniteiterator/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 12:49:28 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[infiniteiterator]]></category>
		<category><![CDATA[spl]]></category>

		<guid isPermaLink="false">http://cowburn.info/?p=316</guid>
		<description><![CDATA[In an article back in July (Anonymous Functions and Closures (as of PHP 5.3)), I gave an example of looping over a series of values repeatedly. Whilst that example does the job (and introduces the concept of closures) it&#8217;s hardly the most convenient method of repeatedly iterating over a series of values. Introducing the InfiniteIterator [...]]]></description>
				<content:encoded><![CDATA[<p>In an article back in July (<a href="http://cowburn.info/2009/07/08/anonymous-closures/" title="Read Anonymous Functions and Closures (as of PHP 5.3)">Anonymous Functions and Closures (as of PHP 5.3)</a>), I gave <a href="http://cowburn.info/2009/07/08/anonymous-closures/#fig5" title="See example: Cycling with Closures">an example</a> of looping over a series of values repeatedly.  Whilst that example does the job (and introduces the concept of closures) it&#8217;s hardly the most convenient method of repeatedly iterating over a series of values.  Introducing the <a href="http://php.net/InfiniteIterator" title="PHP Manual: InfiniteIterator"><code>InfiniteIterator</code></a> which is part of the <a href="http://php.net/spl" title="Standard PHP Library">Standard PHP Library</a> (SPL).<span id="more-316"></span></p>
<p>On the plus side, for those who have yet to take the plunge into using PHP 5.3, this iterator has been part of the core of PHP as of 5.1.0 so there is a much greater chance of actually being able to use it right now.  Bear in mind that the SPL is supposed to work together with its component parts so if <a href="http://php.net/iterator" title="PHP: Object Iteration">iterators</a> are a foreign concept, some of this post might be a little unclear but it is not the purpose of this post to outline iterators in PHP.</p>
<p>As eluded to above, the <code>InfiniteIterator</code> comes in useful when you have an existing <code>Iterator</code> (anything that implements that interface; a directory listing (<code>DirectoryIterator</code>), a file (<code>SplFileObject</code>), an array (with <code>ArrayIterator</code>), and so on) and wish to iterate over its contents again and again. </p>
<h3>An <code>InfiniteIterator</code> Example</h3>
<p>Here is a basic example that I wrote for the <a href="http://php.net/InfiniteIterator.construct" title="PHP Manual: InfiniteIterator::__construct">documentation</a>. Note that a <a href="http://php.net/LimitIterator" title="The LimitIterator class"><code>LimitIterator</code></a> is used to restrict the values which are iterated over (otherwise the loop would go on forever!).</p>
<div class="codecolorer-container php twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000088;">$arrayit</span> &nbsp;<span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayIterator<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cat'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'dog'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$infinite</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> InfiniteIterator<span style="color: #009900;">&#40;</span><span style="color: #000088;">$arrayit</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$limit</span> &nbsp; &nbsp;<span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LimitIterator<span style="color: #009900;">&#40;</span><span style="color: #000088;">$infinite</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$value</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>This example outputs something along the lines of:</p>
<div class="codecolorer-container plain twitlight moo-highlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="plain codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cat<br />
dog<br />
cat<br />
dog<br />
cat<br />
dog<br />
cat</div></div>
<p>Can you think of any more useful instances where the <code>InfiniteIterator</code> might come in useful?</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cowburn?a=IXtnrxwCnu8:KJMFyRqfXJQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cowburn?i=IXtnrxwCnu8:KJMFyRqfXJQ:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cowburn/~4/IXtnrxwCnu8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://cowburn.info/2009/09/25/infiniteiterator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://cowburn.info/2009/09/25/infiniteiterator/</feedburner:origLink></item>
	</channel>
</rss>
