<?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>Ryan Rampersad &#187; PHP</title>
	<atom:link href="http://blog.ryanrampersad.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ryanrampersad.com</link>
	<description>Thoughts, Ideas &#38; Opinions</description>
	<lastBuildDate>Thu, 17 May 2012 17:11:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-beta4-20825</generator>
		<item>
		<title>★ Parse error: syntax error, unexpected T_AS</title>
		<link>http://blog.ryanrampersad.com/2011/10/25/parse-error-syntax-error-unexpected-t_as/</link>
		<comments>http://blog.ryanrampersad.com/2011/10/25/parse-error-syntax-error-unexpected-t_as/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 17:37:22 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Errors]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[loops]]></category>

		<guid isPermaLink="false">http://blog.ryanrampersad.com/?p=4098</guid>
		<description><![CDATA[I was doing some PHP work after a long hiatus. You get used to one language and when you back to another, you just forget things sometimes. I received an unexpected T_AS. Parse error: syntax error, unexpected T_AS, expecting &#8216;;&#8217; in /homepages/224/d19925234/htdocs/kdelli/working/index.php on line 18 The error is so descriptive! Well, more so than others, [...]]]></description>
			<content:encoded><![CDATA[<p>I was doing some PHP work after a long hiatus. You get used to one language and when you back to another, you just forget things sometimes. I received an <em>unexpected T_AS</em>.</p>
<blockquote><p>Parse error: syntax error, unexpected T_AS, expecting &#8216;;&#8217; in /homepages/224/d19925234/htdocs/kdelli/working/index.php on line 18</p></blockquote>
<p>The error is so descriptive! Well, more so than others, actually. When do you use the keyword <code>as</code>? In loop declarations! See my code.</p>
<pre class="brush: php; title: ; notranslate">
if ( $query == &quot;places&quot; ) {
    $output = &quot;&quot;;
    for ($locations as $key =&gt; $l) {
        $output .= $l . &quot;\r\n&quot;;
    }    
}

</pre>
<p>What could be wrong? Take a look at the <em>for loop</em> declaration. Notice anything odd about it? I didn&#8217;t either, at first. The <code>as</code> looks right, I took out <code>$key =&gt;</code> but there was no difference. I realized, since I was coming from Java, that <em>for each loops</em> aren&#8217;t just <em>for loops</em> in PHP. They are literally <code>foreach</code> loops.</p>
<p>I corrected the error simply by changing <code>for</code> to <code>foreach</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ryanrampersad.com/2011/10/25/parse-error-syntax-error-unexpected-t_as/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>★ Upcoming PHP 5.4 Features &#8211; Arrays</title>
		<link>http://blog.ryanrampersad.com/2011/07/25/upcoming-php-5-4-features/</link>
		<comments>http://blog.ryanrampersad.com/2011/07/25/upcoming-php-5-4-features/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 16:59:21 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[updates]]></category>

		<guid isPermaLink="false">http://blog.ryanrampersad.com/?p=3980</guid>
		<description><![CDATA[The post tile was a little misleading. PHP.net has the full changeset for the PHP 5.4alpha. Two remarkable language features coming in PHP 5.4. Array dereferencing, or calling a function and acting upon it directly as if it were an array. In addition, a new short syntax for creating arrays akin to the JavaScript array [...]]]></description>
			<content:encoded><![CDATA[<div class="note">The post tile was a little misleading. PHP.net has the <a href="http://www.php.net/releases/NEWS_5_4_0_alpha1.txt">full changeset for the PHP 5.4alpha</a>.</div>
<p>Two remarkable language <a href="http://svn.php.net/viewvc/php/php-src/branches/PHP_5_4/UPGRADING?view=markup&#038;pathrev=313641">features</a> <a href="http://svn.php.net/viewvc?view=revision&#038;revision=313641">coming in PHP 5.4</a>.</p>
<p>Array dereferencing, or calling a function and acting upon it directly as if it were an array.</p>
<pre class="brush: php; title: ; notranslate">
foo()[0]
$foo-&gt;bar()[0]
</pre>
<p>In addition, a new short syntax for creating arrays akin to the JavaScript array literal syntax.</p>
<pre class="brush: php; title: ; notranslate">
$a = [1, 2, 3, 4];
$b = ['one' =&gt; 1, 'two' =&gt; 2, 'three' =&gt; 3, 'four' =&gt; 4];
$c = ['one' =&gt; 1, 2, 'three' =&gt; 3, 4];
</pre>
<p>These two features will obviously make it impossible to be backwards compatible with older versions of PHP, but that&#8217;s really bad. Sadly, nobody on shared hosting will use this for a couple years.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ryanrampersad.com/2011/07/25/upcoming-php-5-4-features/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>★ PHP 5.4 &amp; WordPress Compatiability</title>
		<link>http://blog.ryanrampersad.com/2011/07/10/php-5-4-wordpress-compatiability/</link>
		<comments>http://blog.ryanrampersad.com/2011/07/10/php-5-4-wordpress-compatiability/#comments</comments>
		<pubDate>Sun, 10 Jul 2011 14:49:09 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://blog.ryanrampersad.com/?p=3779</guid>
		<description><![CDATA[PHP 5.4 compatibility warnings on creating default object from empty value. The WordPress trac had a ticket filed that mentions PHP 5.4 and I mentioned its imminent arrival in the wake of a very specific host not supporting even the latest stable version of PHP 5.3 officially. I wonder about the future of PHP.]]></description>
			<content:encoded><![CDATA[<p><a href="http://core.trac.wordpress.org/ticket/18049">PHP 5.4 compatibility warnings on creating default object from empty value</a>.</p>
<p>The WordPress trac had a ticket filed that mentions PHP 5.4 and <a href="http://blog.ryanrampersad.com/2011/06/22/and-now-php-5-4/" title="And Now PHP 5.4">I mentioned its imminent arrival</a> in the wake of a very specific host <a href="http://blog.ryanrampersad.com/2011/06/19/php-5-3-not-on-1and1-yet/" title="PHP 5.3 – Not on 1and1 Yet">not supporting even the latest stable version of PHP 5.3</a> officially.</p>
<p class="signoff"><em>I wonder about the future of PHP.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ryanrampersad.com/2011/07/10/php-5-4-wordpress-compatiability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>★ PHP 5.3.99-dev on 1and1</title>
		<link>http://blog.ryanrampersad.com/2011/06/22/php-5-3-99-dev-on-1and1/</link>
		<comments>http://blog.ryanrampersad.com/2011/06/22/php-5-3-99-dev-on-1and1/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 23:02:37 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Rants]]></category>
		<category><![CDATA[unified]]></category>

		<guid isPermaLink="false">http://blog.ryanrampersad.com/?p=3509</guid>
		<description><![CDATA[A few days after wondering where PHP 5.3 support was on 1and1, I found this little gem in the 1and1 FAQ: PHP 6 support. The full document explains that you can but shouldn&#8217;t enable PHP 6 because it&#8217;s in developmental stages. When I throw an .htaccess file with the PHP6-ify directive, AddType x-mapp-php6 .php, in [...]]]></description>
			<content:encoded><![CDATA[<p>A few days after <a href="http://blog.ryanrampersad.com/2011/06/19/php-5-3-not-on-1and1-yet/" title="PHP 5.3 – Not on 1and1 Yet">wondering where PHP 5.3 support was on 1and1</a>, I found this little gem in the 1and1 FAQ: <a href="http://www.1and1php.com/phpinfo.php6">PHP 6 support</a>. The <a href="http://faq.1and1.com/scripting_languages_supported/php/4.html">full document explains</a> that you <em>can</em> but <em>shouldn&#8217;t</em> enable PHP 6 because it&#8217;s in developmental stages. When I throw an <code>.htaccess</code> file with the PHP6-ify directive, <code>AddType x-mapp-php6 .php</code>, in the same folder as a phpinfo call, I get a lovely little message:</p>
<blockquote><p>PHP Version 5.3.99-dev</p></blockquote>
<p>So, maybe we have something here.</p>
<p><a href="http://blog.ryanrampersad.com/wp-content/uploads/2011/06/php-6-dev-5399.png"><img src="http://blog.ryanrampersad.com/wp-content/uploads/2011/06/php-6-dev-5399-580x185.png" alt="PHP 6 Development - PHP 5.3.99-dev" title="PHP 6 Development - PHP 5.3.99-dev" width="580" height="185" class="aligncenter size-medium wp-image-3505" /></a></p>
<p><del datetime="2011-06-22T22:53:29+00:00">I have yet to check if this really enables PHP 5.3 support or if just does something funky with the version numbers.</del> I tested the <code>.htaccess</code> PHP-6 enabled directory with a little test script from the PHP 5.3 <a href="http://php.net/manual/en/functions.anonymous.php">anonymous functions page</a>.</p>
<pre class="brush: php; title: ; notranslate">
// from http://php.net/manual/en/functions.anonymous.php #example-1
echo preg_replace_callback('~-([a-z])~', function ($match) {
    return strtoupper($match[1]);
}, 'hello-world');
// outputs helloWorld


// from http://php.net/manual/en/functions.anonymous.php #example-2
$greet = function($name)
{
    printf(&quot;Hello %s\r\n&quot;, $name);
};

$greet('World');
$greet('PHP');
// Hello World Hello PHP
</pre>
<p>When I test this without the special <code>.htaccess</code>, it spews a PHP 5.2 error, a function is in the wrong place.</p>
<blockquote><p>
Parse error: syntax error, unexpected T_FUNCTION in /homepages/27/d199890134/htdocs/dev/test.php on line 4</p></blockquote>
<p>With the directive, I get lovely results with no errors. So perhaps you&#8217;ll want to try this out.</p>
<blockquote><pre>helloWorldHello World Hello PHP</pre>
</blockquote>
<p>It looks like we just found PHP 5.3, albeit in a round-about way. Again, I&#8217;m not 100% sure that this is true PHP 5.3 support and it could be that it is an untuned and sloppy trunk build that has loads of bugs and whatnot.</p>
<div class="warning">If this works for you, leave a comment. I&#8217;m going to guess it won&#8217;t universally work through different packages.</div>
<div class="note">
<h3>August 8th, 2011</h3>
<p>Some of the commenters tried this method and for some time they did find a PHP 5.3 level of functionality. Recently though they have been finding <strong>PHP 5.4alpha1</strong>. <em>I would not recommend this for production as it apparently changes all the time.</em>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.ryanrampersad.com/2011/06/22/php-5-3-99-dev-on-1and1/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>★ PHP 5.3 &#8211; Not on 1and1 Yet</title>
		<link>http://blog.ryanrampersad.com/2011/06/19/php-5-3-not-on-1and1-yet/</link>
		<comments>http://blog.ryanrampersad.com/2011/06/19/php-5-3-not-on-1and1-yet/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 04:53:07 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[unified]]></category>

		<guid isPermaLink="false">http://blog.ryanrampersad.com/?p=3453</guid>
		<description><![CDATA[Update: June 2011 Maybe there is PHP 5.3 support on 1and1. I wanted to use a certain wonderful PHP 5.3 framework for an upcoming project. I needed the official word on the state of PHP 5.3 on my beloved host, 1and1. I sent off an email to technical customer support. Here&#8217;s the email I sent [...]]]></description>
			<content:encoded><![CDATA[<div class="note">
<h3>Update: June 2011</h3>
<p>Maybe <a href="http://blog.ryanrampersad.com/2011/06/22/php-5-3-99-dev-on-1and1/">there is PHP 5.3 support on 1and1</a>.
</div>
<p>I wanted to use a certain wonderful PHP 5.3 framework for an upcoming project. I needed the official word on the state of PHP 5.3 on my beloved host, 1and1. I sent off an email to technical customer support.</p>
<p>Here&#8217;s the email I sent off this morning.</p>
<blockquote><p>
Hey there. I was wondering if it was possible to enable PHP 5.3 on 1and1 shared hosting servers? PHP 5.3 has been recommended since July 2010 and as it is a year later, 1and1 servers should be able to use it. </p>
<p>I checked my control panel and I can toggle the global PHP version to PHP 4, PHP 5 and something called PHP dev, but it is not particularly clear if PHP dev is PHP 5.3. I set my global version to PHP dev but my phpinfo() function still returns 5.2.17.</p>
<p>It would be really fantastic if I had access to PHP 5.3 because I may have to consider alternative hosting accommodations otherwise.</p>
<p>Thank you and have a good one.</p>
<p>&#8211;<br />
Contract ID:  xxxxxx; Customer ID:  xxxxxx<br />
&#8211;<br />
Ryan Rampersad<br />
www.ryanrampersad.com
</p></blockquote>
<p>Since it was Sunday, I didn&#8217;t expect a reply so soon. But here it is in its full unedited glory.</p>
<blockquote><p>
Dear Customer,</p>
<p>Thank you for contacting us.</p>
<p>As we had double check further, as of this moment, we only run php version 5.2.17. Our system administrator as still on the process of upgrading of php version to php 5.3 version.</p>
<p>If you have any further questions please do not hesitate to contact us.</p>
<p>&#8211;<br />
Sincerely,<br />
xxxxxxx xxxxxxxxx<br />
Technical Support<br />
1&#038;1 Internet
</p></blockquote>
<p>Well, that&#8217;s definitive, isn&#8217;t it? They had to double check, but the system admininstrator is still slowly typing out that <em>apt-get</em> command to update to the latest version of PHP. But really, can I expect more from 1and1? With my blog slowly creeping up to the memory limitations and quite probably the daytime-peak connection traffic, I might be tempted to change. Or not.</p>
<p>So, please 1and1, get on this because I really need PHP 5.3!</p>
<div class="warning">Readers: if you have 1and1 as a host and found this page via Google or some other search engine, <strong>please leave a comment</strong>. It spreads the awareness.</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.ryanrampersad.com/2011/06/19/php-5-3-not-on-1and1-yet/feed/</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
		<item>
		<title>★ PHP sprintf &amp; string literals</title>
		<link>http://blog.ryanrampersad.com/2011/05/17/php-sprintf-string-literals/</link>
		<comments>http://blog.ryanrampersad.com/2011/05/17/php-sprintf-string-literals/#comments</comments>
		<pubDate>Tue, 17 May 2011 18:40:45 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[unified]]></category>

		<guid isPermaLink="false">http://blog.ryanrampersad.com/?p=2830</guid>
		<description><![CDATA[I wanted to do some string abstractions in PHP today. I setup my configuration by defining the string templates as constants. That looks great and like it would work, doesn&#8217;t it? It does not work. Why? Have you ever seen a tutorial or some code written by some else using a $variable inside of a [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to do some string abstractions in PHP today. I setup my configuration by defining the string templates as constants.</p>
<pre class="brush: php; title: ; notranslate">
define(&quot;LOG_FILENAME&quot;, &quot;logs/%1$s-%2$s.txt&quot;);
</pre>
<p>That looks great and like it would work, doesn&#8217;t it? It does not work. Why? Have you ever seen a tutorial or some code written by some else using a <code>$variable</code> inside of a string intentionally?</p>
<pre class="brush: php; title: ; notranslate">
 $name = &quot;Ryan&quot;;
 echo &quot;$name is awesome!&quot;;
</pre>
<p>That&#8217;s not right. It should be concatenated together because this is confusing. Is it printing <em>$name</em> or the variable in <em>$name</em>? None of the other languages I use do this kind of $inline variable inflation. It bothers me.</p>
<p>My code today was using sprintf to fill in the variables from the filename template established earlier.</p>
<pre class="brush: php; title: ; notranslate">
 $logfile = sprintf(LOG_FILENAME, $user, $date);
</pre>
<p>After doing some testing and noticing that my log files were coming up as <em>-.txt</em>, I realized there was a problem with the strings.</p>
<p>I looked over my template <code>"logs/%1$s-%2$s.txt"</code> and saw the problem. The <code>$s</code> were uninitialized variables being treated as empty strings! To fix the obvious problem of interpreted strings, I changed them to literals. That is, with single quotes: <code>'logs/%1$s-%2$s.txt'</code>.</p>
<p>That fixed the problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ryanrampersad.com/2011/05/17/php-sprintf-string-literals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>★ Multiple Column Orders in mysql</title>
		<link>http://blog.ryanrampersad.com/2010/12/15/ordering-multiple-columns-in-mysql/</link>
		<comments>http://blog.ryanrampersad.com/2010/12/15/ordering-multiple-columns-in-mysql/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 19:26:21 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[unified]]></category>

		<guid isPermaLink="false">http://blog.ryanrampersad.com/?p=2321</guid>
		<description><![CDATA[I rarely have to double order my resultant rows in most projects. I had to look this up however, to understand how to order my rows in, not one, but two different ways. It turns out that&#8217;s it easy and pretty neat. Let&#8217;s say you have two columns that describe two common pieces of data, [...]]]></description>
			<content:encoded><![CDATA[<p>I rarely have to double order my resultant rows in most projects. I had to <a href="http://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html">look this up</a> however, to understand how to order my rows in, not one, but two different ways. It turns out that&#8217;s it easy and pretty neat.</p>
<p><a href="http://blog.ryanrampersad.com/wp-content/uploads/2010/07/mysql_multi_columns.png"><img src="http://blog.ryanrampersad.com/wp-content/uploads/2010/07/mysql_multi_columns.png" alt="A snapshot of notepad++ with a code sample demonstrating a live query of multiple row orders" title="Multiple Row Orders" width="580" height="132" class="aligncenter size-full wp-image-2322" /></a></p>
<p>Let&#8217;s say you have two columns that describe two common pieces of data, <em>first names</em> and <em>last names</em>. If you wanted to order everyone by first name, it would be done easily by <code>ORDER BY first_name</code>. But then, if you wanted also to have those names in order by last name too? Easy. Simply add a comma: <code>ORDER BY first_name, last_name</code>.</p>
<p>But there&#8217;s more! For instance, if you wanted, you could order the last names in ascending order (A through Z) but have the first names in descending order (Z through A) like so, <code>ORDER BY last_name ASC, first_name DESC</code>. Each   column can have it&#8217;s own ordering direction.</p>
<p>If you can add two columns, you can also add three, or four, or more. For instance, like the name ordering scheme previously, adding in age to further order these people is possible: <code>ORDER BY first_name, last_name, age</code>.</p>
<p>That&#8217;s all there is to ordering multiple columns in mysql.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ryanrampersad.com/2010/12/15/ordering-multiple-columns-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>★ Symfony &#8211; Production index.php not working</title>
		<link>http://blog.ryanrampersad.com/2010/12/09/symfony-production-index-php-not-working/</link>
		<comments>http://blog.ryanrampersad.com/2010/12/09/symfony-production-index-php-not-working/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 00:44:24 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[unified]]></category>

		<guid isPermaLink="false">http://blog.ryanrampersad.com/?p=2439</guid>
		<description><![CDATA[I normally work exclusively in frontend_dev.php mode while working on symfony apps. But on occasion I&#8217;ll switch over to the index.php production mode. When I switched, my entire app failed. Miserably. I would use a known URL such as example.com/categories/5/tech-stuff and I would get a Not Found error in return. I thought at first that [...]]]></description>
			<content:encoded><![CDATA[<p>I normally work exclusively in <em>frontend_dev.php</em> mode while working on symfony apps. But on occasion I&#8217;ll switch over to the <em>index.php</em> production mode. When I switched, my entire app failed. Miserably. I would use a known URL such as <em>example.com/categories/5/tech-stuff</em> and I would get a <strong>Not Found</strong> error in return.</p>
<p><a href="http://blog.ryanrampersad.com/wp-content/uploads/2010/08/symfony-index-not-found.png"><img src="http://blog.ryanrampersad.com/wp-content/uploads/2010/08/symfony-index-not-found.png" alt="" title="Symfony - index.php not found" width="580" height="259" class="alignright size-full wp-image-2440" /></a></p>
<p>I thought at first that this problem was an htaccess issue. So I headed over to <em>/web/.htaccess</em>. The docs in the file specifically say that if no_name_script doesn&#8217;t work, try the following line.</p>
<blockquote><p># uncomment the following line, if you are having trouble<br />
  # getting no_script_name to work<br />
  RewriteBase /</p></blockquote>
<p>That didn&#8217;t solve the problem. I still received lovely <em>not found</em> errors. Those errors were not appearing when I used the front_end development mode, so it was something else. I had recently reinstalled my server and I wondered if that had something to do with it. I went to take a look at what extensions apache2 on Ubuntu was automatically installed with.</p>
<p>The big surprise: mod_rewrite was <em>not</em> enabled automatically! So after enabling it quickly with <code>sudo a2enmod rewrite</code> and restarting apache2 with the change <nobr><code>sudo service apache2 restart</code></nobr>, everything worked just fine.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ryanrampersad.com/2010/12/09/symfony-production-index-php-not-working/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>★ PHP Array to String</title>
		<link>http://blog.ryanrampersad.com/2010/09/29/php-array-to-string/</link>
		<comments>http://blog.ryanrampersad.com/2010/09/29/php-array-to-string/#comments</comments>
		<pubDate>Wed, 29 Sep 2010 21:48:37 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[unified]]></category>

		<guid isPermaLink="false">http://blog.ryanrampersad.com/?p=2329</guid>
		<description><![CDATA[In Java, you can easily force an array to a string representation. It is invaluable when debugging to able to do this, and while PHP does not provide an obviously named function (or method) for this functionality, it is easy to implement. You can of course, run off an array with a simple var_dump No [...]]]></description>
			<content:encoded><![CDATA[<p>In Java, you can easily force an array to a string representation. It is invaluable when debugging to able to do this, and while PHP does not provide an obviously named function (or method) for this functionality, it is easy to  implement.</p>
<p>You can  of course, run off an array with a simple <code>var_dump</code> No big deal there, except you know, formatting and the verbosity of the indents, how many items are in each subarray and on. A more elegant solution is to make a customized function that can imiate the Java method, <code>Arrays.toString(array)</code>.</p>
<p>This fulfilled my needs for a quick and easy <em>array to string</em> function.</p>
<pre class="brush: php; title: ; notranslate">
function array_to_string($array, $options = array()) {
    $options =  array_merge(array(
      &quot;html&quot; =&gt; array(&quot;open&quot; =&gt; &quot;&lt;pre&gt;&quot;, &quot;close&quot; =&gt; &quot;&lt;/pre&gt;&quot;),
      &quot;enclose&quot; =&gt; array(&quot;open&quot; =&gt; &quot;[&quot;, &quot;close&quot; =&gt; &quot;]&quot;),
      &quot;separator&quot; =&gt; &quot;, &quot;
    ), $options);

    $output = $options[&quot;html&quot;][0];
    $output = $options[&quot;enclose&quot;][0];

    $output = implode($options[&quot;separator&quot;], $array);

    $output = $options[&quot;enclose&quot;][1];
    $output = $options[&quot;html&quot;][1];

    return $output;
}
</pre>
<p>The function has a few options, it allows you to specify opening and closing tags, defaulting to &lt;pre&gt;, also the opening and closing enclosure symbols, defaulting to square brackets. Finally, the customary glue or separator, <span title="this was excellent">commonly a comma</span>. One downside to this method is that it assumes $array is not multidimensional. It would take some iteration or recursion to truly come up with a perfect solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ryanrampersad.com/2010/09/29/php-array-to-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>★ Include partial from app/template directory in symfony</title>
		<link>http://blog.ryanrampersad.com/2010/09/23/include-partial-from-apptemplate-directory-in-symfony/</link>
		<comments>http://blog.ryanrampersad.com/2010/09/23/include-partial-from-apptemplate-directory-in-symfony/#comments</comments>
		<pubDate>Thu, 23 Sep 2010 23:36:45 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[unified]]></category>

		<guid isPermaLink="false">http://blog.ryanrampersad.com/?p=2443</guid>
		<description><![CDATA[In Symfony, the sfDoctrinePager is awesome. To make it more reusable though, I made partial in the app/template/ directory so that I could include in on any page that needed pagination. Of course, that&#8217;s when I got an error! 500 &#124; Internal Server Error &#124; sfRenderException The template &#8220;_paginate.php&#8221; does not exist or is unreadable [...]]]></description>
			<content:encoded><![CDATA[<p>In Symfony, the <em>sfDoctrinePager</em> is awesome. To make it more reusable though, I made partial in the <em>app/template/</em> directory so that I could include in on any page that needed pagination. Of course, that&#8217;s when I got an error!</p>
<p><a href="http://blog.ryanrampersad.com/wp-content/uploads/2010/08/sf-partial-error.png"><img src="http://blog.ryanrampersad.com/wp-content/uploads/2010/08/sf-partial-error.png" alt="" title="Symfony - Could Not Find Pager" width="580" height="211" class="alignright size-full wp-image-2444" /></a></p>
<blockquote><p>
500 | Internal Server Error | sfRenderException<br />
The template &#8220;_paginate.php&#8221; does not exist or is unreadable in &#8220;&#8221;.
</p></blockquote>
<p>My assumption was that if symfony was given <code>/paginate</code> as a name for the partial name, it would get the hint that it was being stored in <em>app/templates/</em>. But that wasn&#8217;t the case, because the error persisted. I wasn&#8217;t sure if symfony could even do this, but then how could this super powerful framework <em>not support</em> including partials from the main template directory? Impossible.</p>
<p>So I looked up the documentation for the <code>include_partial</code> function. Well, <a href="http://www.symfony-project.org/api/search/1_4?search=include+partial">it wasn&#8217;t found</a>. Instead, doing a quick google turned up the <a href="http://www.symfony-project.org/api/1_4/PartialHelper">PartialHelper</a> instead, which was I was looking for.</p>
<p>It turns out that the <code>include_partial</code function has the functionality I was hoping for. To include a partial from the main templates folder, all I needed to do was simply add <em>global</em> as the module name.</p>
<blockquote><p>If the module name is 'global', then the partial file is looked for in myapp/templates/. </p></blockquote>
<p>So, to include my paginate partial, I called <code>include_partial("global/paginate", array("pager"=>$pager, "url"=>url_for("collection/index"));</code>. That's all there is to including a partial in symfony from the app/template folder.</p>
<p>Happy partials.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ryanrampersad.com/2010/09/23/include-partial-from-apptemplate-directory-in-symfony/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

