<?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>Squirrel Hacker &#187; WTF</title>
	<atom:link href="http://blog.seanja.com/category/wtf/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.seanja.com</link>
	<description>I have come forward in time from the year 1986 to share this with you</description>
	<lastBuildDate>Mon, 06 Feb 2012 12:38:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How stupid do you think I am?</title>
		<link>http://blog.seanja.com/2011/07/how-stupid-do-you-think-i-am/</link>
		<comments>http://blog.seanja.com/2011/07/how-stupid-do-you-think-i-am/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 03:30:46 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[WTF]]></category>
		<category><![CDATA[Checks In The Mail]]></category>
		<category><![CDATA[E-mail]]></category>
		<category><![CDATA[Inc.]]></category>
		<category><![CDATA[Mail! Inc.]]></category>
		<category><![CDATA[Password]]></category>
		<category><![CDATA[Spamming]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=38835</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/07/how-stupid-do-you-think-i-am/' addthis:title='How stupid do you think I am? '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Really guys? From: ************@live.com Reply-to: dovmax@gmail.com Dear Valid User, Our Account users discovered series of illegal attempts on your mail account from different IP locations.This is for your own safety to avoid your account closed, you will have to verify your account by filling out your Log-in below by clicking the reply button. We apologies [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/07/how-stupid-do-you-think-i-am/' addthis:title='How stupid do you think I am? ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2008/07/spartan-coding/' rel='bookmark' title='Spartan Coding'>Spartan Coding</a></li>
<li><a href='http://blog.seanja.com/2009/02/twitter-updates-for-2009-02-23/' rel='bookmark' title='Twitter Updates for 2009-02-23'>Twitter Updates for 2009-02-23</a></li>
<li><a href='http://blog.seanja.com/2009/02/twitter-updates-for-2009-02-23-2/' rel='bookmark' title='Twitter Updates for 2009-02-23'>Twitter Updates for 2009-02-23</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/07/how-stupid-do-you-think-i-am/' addthis:title='How stupid do you think I am? '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Really guys?</p>
<blockquote>
<p>From: ************@live.com<br />
Reply-to: dovmax@gmail.com</p>
<p>Dear Valid User,<br />
    Our Account users discovered series of illegal attempts on your mail account from different IP locations.This is for your own safety to avoid your account closed, you will have to verify your account by filling out your Log-in below by clicking the reply button. We apologies for any inconveniences.</p>
<p>User name:&#8230;&#8230;&#8230;&#8230;&#8230;..<br />
Password:&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<br />
Date Of Birth:&#8230;&#8230;&#8230;&#8230;.<br />
Occupation:&#8230;&#8230;&#8230;&#8230;&#8230;.<br />
Country Of Residence:&#8230;&#8230;</p>
<p>After receiving the information requested you will be able to continue using your Account.</p>
<p>Customer Care<br />
71594822<br />
Copyright © 2011 Mail! Inc. (Co. Reg. No. 2344507D)All Rights Reserved. Intellectual Property Rights Policy.
</p></blockquote>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/07/how-stupid-do-you-think-i-am/' addthis:title='How stupid do you think I am? ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2008/07/spartan-coding/' rel='bookmark' title='Spartan Coding'>Spartan Coding</a></li>
<li><a href='http://blog.seanja.com/2009/02/twitter-updates-for-2009-02-23/' rel='bookmark' title='Twitter Updates for 2009-02-23'>Twitter Updates for 2009-02-23</a></li>
<li><a href='http://blog.seanja.com/2009/02/twitter-updates-for-2009-02-23-2/' rel='bookmark' title='Twitter Updates for 2009-02-23'>Twitter Updates for 2009-02-23</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2011/07/how-stupid-do-you-think-i-am/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>You are doing it wrong&#8230;</title>
		<link>http://blog.seanja.com/2011/06/you-are-doing-it-wrong/</link>
		<comments>http://blog.seanja.com/2011/06/you-are-doing-it-wrong/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 14:57:37 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[WTF]]></category>
		<category><![CDATA[Human Interest]]></category>
		<category><![CDATA[Social Issues]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=38828</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/06/you-are-doing-it-wrong/' addthis:title='You are doing it wrong&#8230; '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>If you are putting this at the top of every file&#8230; // i will keep yelling this // DON'T FORGET TO START THE SESSION !!! session_start&#40;&#41;; You may just be doing php wrong&#8230; and I hate you Related posts: PHP Functions, you&#8217;re doing it wrong&#8230; PHP SQL Query Builder Job Search Results<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/06/you-are-doing-it-wrong/' addthis:title='You are doing it wrong&#8230; ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/' rel='bookmark' title='PHP Functions, you&#8217;re doing it wrong&#8230;'>PHP Functions, you&#8217;re doing it wrong&#8230;</a></li>
<li><a href='http://blog.seanja.com/2011/01/php-sql-query-builder/' rel='bookmark' title='PHP SQL Query Builder'>PHP SQL Query Builder</a></li>
<li><a href='http://blog.seanja.com/2008/08/job-search-results/' rel='bookmark' title='Job Search Results'>Job Search Results</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/06/you-are-doing-it-wrong/' addthis:title='You are doing it wrong&#8230; '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>If you are putting this at the top of every file&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// i will keep yelling this</span>
<span style="color: #666666; font-style: italic;">// DON'T FORGET TO START THE SESSION !!!</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You may just be doing php wrong&#8230; and I hate you</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/06/you-are-doing-it-wrong/' addthis:title='You are doing it wrong&#8230; ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/' rel='bookmark' title='PHP Functions, you&#8217;re doing it wrong&#8230;'>PHP Functions, you&#8217;re doing it wrong&#8230;</a></li>
<li><a href='http://blog.seanja.com/2011/01/php-sql-query-builder/' rel='bookmark' title='PHP SQL Query Builder'>PHP SQL Query Builder</a></li>
<li><a href='http://blog.seanja.com/2008/08/job-search-results/' rel='bookmark' title='Job Search Results'>Job Search Results</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2011/06/you-are-doing-it-wrong/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UBB AVP&#8230; same difference</title>
		<link>http://blog.seanja.com/2011/03/ubb-avp-same-difference/</link>
		<comments>http://blog.seanja.com/2011/03/ubb-avp-same-difference/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 03:20:42 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[postaweek2011]]></category>
		<category><![CDATA[WTF]]></category>
		<category><![CDATA[Bull shit]]></category>
		<category><![CDATA[Competition]]></category>
		<category><![CDATA[Marketing]]></category>
		<category><![CDATA[Price]]></category>
		<category><![CDATA[Pricing]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=38724</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/03/ubb-avp-same-difference/' addthis:title='UBB AVP&#8230; same difference '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Sadly this seems completely accurate&#8230; In order to be effective as an economic ITMP, the usage based price component needs to be established so as to discourage use above the set limit. The price should incent use in excess of the limit only to the extent that the consumer would gain significant value from that [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/03/ubb-avp-same-difference/' addthis:title='UBB AVP&#8230; same difference ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2009/08/are-you-a-cobol-programmer/' rel='bookmark' title='Are You a COBOL Programmer?'>Are You a COBOL Programmer?</a></li>
<li><a href='http://blog.seanja.com/2008/12/caveat-emptor/' rel='bookmark' title='Caveat Emptor'>Caveat Emptor</a></li>
<li><a href='http://blog.seanja.com/2008/09/a-look-at-postgresql/' rel='bookmark' title='A look at PostgreSQL'>A look at PostgreSQL</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/03/ubb-avp-same-difference/' addthis:title='UBB AVP&#8230; same difference '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Sadly this seems completely accurate&#8230;</p>
<blockquote><p>
In order to be effective as an economic ITMP, the usage based price component needs to be established so as to discourage use above the set limit. The price should incent use in excess of the limit only to the extent that the consumer would gain significant value from that usage. If the price is set substantially below the consumer’s value, it will have little influence on usage.
</p></blockquote>
<p>via: <a href="http://www.michaelgeist.ca/content/view/5711/125/">http://www.michaelgeist.ca/content/view/5711/125/</a></p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/03/ubb-avp-same-difference/' addthis:title='UBB AVP&#8230; same difference ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2009/08/are-you-a-cobol-programmer/' rel='bookmark' title='Are You a COBOL Programmer?'>Are You a COBOL Programmer?</a></li>
<li><a href='http://blog.seanja.com/2008/12/caveat-emptor/' rel='bookmark' title='Caveat Emptor'>Caveat Emptor</a></li>
<li><a href='http://blog.seanja.com/2008/09/a-look-at-postgresql/' rel='bookmark' title='A look at PostgreSQL'>A look at PostgreSQL</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2011/03/ubb-avp-same-difference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It is like driving a new car off a cliff</title>
		<link>http://blog.seanja.com/2011/02/it-is-like-driving-a-new-car-off-a-cliff/</link>
		<comments>http://blog.seanja.com/2011/02/it-is-like-driving-a-new-car-off-a-cliff/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 05:03:36 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[piwik]]></category>
		<category><![CDATA[WTF]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[free open source web analytics]]></category>
		<category><![CDATA[GerixSoft Ltd.]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Google Inc.]]></category>
		<category><![CDATA[hostgator]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[mod_security]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[representative in our Technical Support department]]></category>
		<category><![CDATA[seanja.com]]></category>
		<category><![CDATA[Technology_Internet]]></category>
		<category><![CDATA[urgh]]></category>
		<category><![CDATA[web analytics]]></category>
		<category><![CDATA[wtf]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=38448</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/02/it-is-like-driving-a-new-car-off-a-cliff/' addthis:title='It is like driving a new car off a cliff '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>So&#8230; This was fun&#8230; Welcome to GatorChat! You are being connected to a representative in our Technical Support department right now. For immediate answers to your questions, check out our knowledge base and video tutorials at http://support.hostgator.com. Your Chat ID is 3333053. Your question is, &#8220;My primary domain is seanja.com. mod_security&#8221; (10:03:41 PM) System: There [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/02/it-is-like-driving-a-new-car-off-a-cliff/' addthis:title='It is like driving a new car off a cliff ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2008/10/twitter-updates-for-2008-10-18/' rel='bookmark' title='Twitter Updates for 2008-10-18'>Twitter Updates for 2008-10-18</a></li>
<li><a href='http://blog.seanja.com/2008/11/twitter-updates-for-2008-11-05/' rel='bookmark' title='Twitter Updates for 2008-11-05'>Twitter Updates for 2008-11-05</a></li>
<li><a href='http://blog.seanja.com/2009/04/links-for-2009-04-08/' rel='bookmark' title='links for 2009-04-08'>links for 2009-04-08</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/02/it-is-like-driving-a-new-car-off-a-cliff/' addthis:title='It is like driving a new car off a cliff '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>So&#8230; This was fun&#8230;</p>
<blockquote><p>
Welcome to GatorChat!</p>
<p>You are being connected to a representative in our Technical Support department right now.</p>
<p>For immediate answers to your questions, check out our knowledge base and video tutorials at http://support.hostgator.com.</p>
<p>Your Chat ID is 3333053.</p>
<p>Your question is, &#8220;My primary domain is seanja.com. mod_security&#8221;</p>
<p>(10:03:41 PM) System: There are currently 3 people in front of you and 86 chat technicians assisting customers.<br />
(10:04:10 PM) System: There are currently 3 people in front of you and 86 chat technicians assisting customers.<br />
(10:04:41 PM) System: There are currently 1 people in front of you and 86 chat technicians assisting customers.<br />
(10:05:11 PM) System: There are currently 0 people in front of you and 87 chat technicians assisting customers.<br />
(10:05:12 PM) <strong style="color:#C00">Gator Tech Support</strong>: has entered the chat.<br />
(10:05:18 PM) <strong style="color:#C00">Gator Tech Support</strong>: Hello, welcome to HostGator Live Chat.<br />
(10:05:32 PM) <strong style="color:#00C">SeanJA</strong>: hi<br />
(10:05:44 PM) <strong style="color:#C00">Gator Tech Support</strong>: How may I assist you today?<br />
(10:06:40 PM) <strong style="color:#00C">SeanJA</strong>: I keep getting a 403 error when trying to use piwik as a tracking server&#8230; I have also run into this problem with drupal&#8217;s &#8216;shurly&#8217; module and the oauth login module as well&#8230; I believe that it would be related to mod_security?<br />
(10:07:55 PM) <strong style="color:#C00">Gator Tech Support</strong>: It really depends<br />
(10:07:55 PM) <strong style="color:#00C">SeanJA</strong>: I got around the one for oauth and shurly (a bit of hackery in drupal core that I would have liked to avoid&#8230;) but the one for piwik seems to be a bit more difficult to get around&#8230;<br />
(10:08:07 PM) <strong style="color:#00C">SeanJA</strong>: http://stats.seanja.com/piwik.php?idsite=1&#038;rec=1&#038;rand=0.11890891543589532&#038;h=0&#038;m=7&#038;s=23&#038;url=http%3A%2F%2Fseanja.com%2F&#038;urlref=&#038;res=1920&#215;1200&#038;cookie=1&#038;pdf=1&#038;qt=1&#038;realp=0&#038;wma=0&#038;dir=0&#038;fla=1&#038;java=1&#038;gears=1&#038;ag=0&#038;action_name=seanja.com<br />
(10:08:11 PM) <strong style="color:#C00">Gator Tech Support</strong>: Here is the mod security http://support.hostgator.com/articles/employees/daily-tasks/mod-sec-and-you<br />
(10:08:20 PM) <strong style="color:#00C">SeanJA</strong>: this is the url giving me the 403 error<br />
(10:08:46 PM) <strong style="color:#C00">Gator Tech Support</strong>: I am seeing a 500 error<br />
(10:09:46 PM) <strong style="color:#00C">SeanJA</strong>: odd&#8230; I am seeing that now too<br />
(10:10:13 PM) <strong style="color:#00C">SeanJA</strong>: oh&#8230; the 500 error is for the ErrorDocument<br />
(10:10:19 PM) <strong style="color:#C00">Gator Tech Support</strong>: here is everything I have on mod_security: <http://support.hostgator.com/articles/employees/daily-tasks/mod-sec-and-you></p>
<p>(10:10:45 PM) <strong style="color:#00C">SeanJA</strong>: I keep getting bounced out to support.hostgator.com<br />
(10:11:05 PM) <strong style="color:#C00">Gator Tech Support</strong>: Yes, all I would be able to do is create a ticket that goes to them.<br />
(10:11:14 PM) <strong style="color:#00C">SeanJA</strong>: http://support.hostgator.com/articles/pre-sales-policies/secfilterengine-and-secfilterscanpost<br />
(10:11:41 PM) <strong style="color:#00C">SeanJA</strong>: this is what prompted me to contact you<br />
(10:12:37 PM) <strong style="color:#C00">Gator Tech Support</strong>: Right, but I see a 500 error<br />
(10:13:52 PM) <strong style="color:#00C">SeanJA</strong>: ok&#8230; but that is for the Error Document, the title of the page is &#8220;Error 403&#8243;<br />
(10:14:24 PM) <strong style="color:#C00">Gator Tech Support</strong>: Right<br />
(10:14:47 PM) <strong style="color:#C00">Gator Tech Support</strong>: Those two are very different errors<br />
(10:14:51 PM) <strong style="color:#00C">SeanJA</strong>: http://forums.hostgator.com/mod-security-and-403-errors-t71394.html<br />
(10:16:09 PM) <strong style="color:#C00">Gator Tech Support</strong>: I understand, a 403, is very different then a 500.<br />
(10:16:54 PM) <strong style="color:#C00">Gator Tech Support</strong>: http://support.hostgator.com/articles/cpanel/internal-server-error-help-500-error<br />
(10:17:30 PM) <strong style="color:#00C">SeanJA</strong>: what I see is:</p>
<p>Error 403 Forbidden,</p>
<p>Also a 500 error was thrown when trying to use ErrorDocument to handle the request<br />
(10:17:58 PM) <strong style="color:#C00">Gator Tech Support</strong>: I am getting:Forbidden</p>
<p>You don&#8217;t have permission to access /piwik.php on this server.</p>
<p>Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.<br />
(10:18:29 PM) <strong style="color:#C00">Gator Tech Support</strong>: That would just need the pwiik.php permissions changed to 644<br />
(10:19:33 PM) <strong style="color:#00C">SeanJA</strong>: if you go to http://stats.seanja.com/piwik.php you actually get a result though<br />
(10:19:42 PM) <strong style="color:#C00">Gator Tech Support</strong>: Piwik is a free open source web analytics alternative to Google analytics.<br />
(10:20:09 PM) <strong style="color:#00C">SeanJA</strong>: as soon as you add ?url=http://test.com to the url it fails to work because the http:// is caught as &#8220;bad&#8221;<br />
(10:20:49 PM) <strong style="color:#C00">Gator Tech Support</strong>: I am getting a page with the following text<br />
(10:20:53 PM) <strong style="color:#C00">Gator Tech Support</strong>: Piwik is a free open source web analytics alternative to Google analytics.<br />
(10:21:00 PM) <strong style="color:#00C">SeanJA</strong>: yep<br />
(10:21:09 PM) <strong style="color:#C00">Gator Tech Support</strong>: Piwik is highlighted and so is web analytics<br />
(10:21:14 PM) <strong style="color:#00C">SeanJA</strong>: and the permissions are set to 664<br />
(10:21:29 PM) <strong style="color:#00C">SeanJA</strong>: well.. 0664<br />
(10:22:32 PM) <strong style="color:#C00">Gator Tech Support</strong>: Right, it is working for me<br />
(10:22:38 PM) <strong style="color:#C00">Gator Tech Support</strong>: Have you cleared your cache?<br />
(10:24:00 PM) <strong style="color:#00C">SeanJA</strong>: hitting the page without and url parameters works fine for me<br />
(10:26:23 PM) <strong style="color:#C00">Gator Tech Support</strong>: Is there anything else I can help you with today?<br />
(10:27:11 PM) <strong style="color:#00C">SeanJA</strong>: is there anyway that you could pass me on to someone that can help me with whitelisting stats.seanja.com/piwik.php from mod_security?<br />
(10:28:11 PM) <strong style="color:#C00">Gator Tech Support</strong>: If you tried to change that, you will cause your site to go down, but I can do that for you if you like<br />
(10:28:27 PM) <strong style="color:#00C">SeanJA</strong>: it will go down?<br />
(10:28:35 PM) <strong style="color:#C00">Gator Tech Support</strong>: It is like driving a new car off a cliff<br />
(10:28:49 PM) <strong style="color:#C00">Gator Tech Support</strong>: If it is not broken you dont want to try and fix it<br />
(10:28:57 PM) <strong style="color:#00C">SeanJA</strong>: it is broken though&#8230;?<br />
(10:29:20 PM) <strong style="color:#C00">Gator Tech Support</strong>: I do not show that<br />
(10:29:48 PM) <strong style="color:#00C">SeanJA</strong>: it has a blanket ignore urls with http:// in them<br />
(10:30:00 PM) <strong style="color:#C00">Gator Tech Support</strong>: A<br />
(10:30:08 PM) <strong style="color:#C00">Gator Tech Support</strong>: Are you trying to show this: http://stats.seanja.com/<br />
(10:31:24 PM) <strong style="color:#C00">Gator Tech Support</strong>: Hello?<br />
(10:31:28 PM) <strong style="color:#00C">SeanJA</strong>: nope&#8230; what /piwik.php does it log a hit to my site<br />
(10:31:53 PM) <strong style="color:#C00">Gator Tech Support</strong>: Ok, what is the php supposed to do?<br />
(10:32:22 PM) <strong style="color:#00C">SeanJA</strong>: on this page: http://seanja.com/tools/unlab-minecraft/<br />
if you look at the net panel in firebug, or the error console in chrome, you will see a 404 for the call to piwik.php?[...]<br />
(10:32:59 PM) <strong style="color:#C00">Gator Tech Support</strong>: I see a picture of a post with yes written on it with graphics of 1996<br />
(10:34:07 PM) <strong style="color:#00C">SeanJA</strong>: yes, but in the error console there is a 403 forbidden error (if you are using chrome: ctrl+shift+i , or firebug F12 in the Net tab (it has to be active on page load though) )<br />
(10:34:23 PM) <strong style="color:#00C">SeanJA</strong>: which means that the hit is not being logged<br />
(10:34:49 PM) <strong style="color:#C00">Gator Tech Support</strong>: I am using firefox<br />
(10:34:58 PM) <strong style="color:#C00">Gator Tech Support</strong>: I will try IE<br />
(10:35:39 PM) <strong style="color:#00C">SeanJA</strong>: probably won&#8217;t show up in IE<br />
(10:35:47 PM) <strong style="color:#C00">Gator Tech Support</strong>: is unlabe a mincraft, yes<br />
(10:36:05 PM) <strong style="color:#C00">Gator Tech Support</strong>: is unlab mincraft up<br />
(10:36:06 PM) <strong style="color:#C00">Gator Tech Support</strong>: yes<br />
(10:37:05 PM) <strong style="color:#00C">SeanJA</strong>: I mean the error in the console (IE&#8217;s console isn&#8217;t great, nor does it exist in IE6/7)<br />
(10:37:29 PM) <strong style="color:#C00">Gator Tech Support</strong>: No, Firefox is fine though.<br />
(10:37:55 PM) <strong style="color:#00C">SeanJA</strong>: do you have firebug installed in firefox?<br />
(10:38:36 PM) <strong style="color:#C00">Gator Tech Support</strong>: Yes<br />
(10:39:20 PM) <strong style="color:#00C">SeanJA</strong>: if you pull it up, and open up the &#8216;Net&#8217; tab, then reload the page you will see the 403 Forbidden error that I am talking about<br />
(10:39:36 PM) <strong style="color:#C00">Gator Tech Support</strong>: I dont see it.<br />
(10:40:07 PM) <strong style="color:#00C">SeanJA</strong>: is the Net tab actually active?<br />
(10:41:25 PM) <strong style="color:#00C">SeanJA</strong>: I think they disabled it by default in recent releases as it slows down page loads considerably on larger sites<br />
(10:41:53 PM) <strong style="color:#C00">Gator Tech Support</strong>: It may be a bug issue but if you just want that mod sec changed I can do that<br />
(10:43:04 PM) <strong style="color:#00C">SeanJA</strong>: I think I have found another way around it&#8230; I will just do what I did to drupal:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// © by Andriy Gerasika from GerixSoft, Ltd.</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_int</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$return</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$return</span> <span style="color: #339933;">==</span> MENU_NOT_FOUND<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://'</span><span style="color: #339933;">,</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$uri</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #990000;">parse_url</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uri</span><span style="color: #339933;">,</span> PHP_URL_PATH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//FIX: SeanJA don't use ereg, use preg_match</span>
<span style="color: #000088;">$paths</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/shurly/api/shorten'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/openid/authenticate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">,</span> <span style="color: #000088;">$paths</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^\/user\/[0-9]+\/openid$/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'q='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$path</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">parse_url</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uri</span><span style="color: #339933;">,</span> PHP_URL_QUERY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'QUERY_STRING'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">;</span>
<span style="color: #990000;">parse_str</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">parse_str</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> menu_execute_active_handler<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>(10:43:26 PM) <strong style="color:#00C">SeanJA</strong>: basically refill the $_GET and $_REQUEST variables before they are checked<br />
(10:44:08 PM) <strong style="color:#C00">Gator Tech Support</strong>: I see<br />
(10:44:09 PM) <strong style="color:#C00">Gator Tech Support</strong>: Is there anything else I can help you with today?<br />
(10:44:14 PM) <strong style="color:#00C">SeanJA</strong>: nope<br />
(10:44:28 PM) <strong style="color:#C00">Gator Tech Support</strong>: Ok, let us know if you have any further questions<br />
(10:44:31 PM) <strong style="color:#C00">Gator Tech Support</strong>: Thank you for using HostGator Live Chat. If you could take a minute to rate your experience with HostGator as well as my overall performance, that would help us to improve our customer service. To do that, just click the button that says Rate and Exit in the upper right hand corner. The survey takes less than a minute to fill out.
</p></blockquote>
<p>In the end, I didn&#8217;t trust him not to screw up my site&#8230; so now I have to do a bunch of hackery to get it to work&#8230;</p>
<p>1 star</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/02/it-is-like-driving-a-new-car-off-a-cliff/' addthis:title='It is like driving a new car off a cliff ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2008/10/twitter-updates-for-2008-10-18/' rel='bookmark' title='Twitter Updates for 2008-10-18'>Twitter Updates for 2008-10-18</a></li>
<li><a href='http://blog.seanja.com/2008/11/twitter-updates-for-2008-11-05/' rel='bookmark' title='Twitter Updates for 2008-11-05'>Twitter Updates for 2008-11-05</a></li>
<li><a href='http://blog.seanja.com/2009/04/links-for-2009-04-08/' rel='bookmark' title='links for 2009-04-08'>links for 2009-04-08</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2011/02/it-is-like-driving-a-new-car-off-a-cliff/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP Functions, you&#8217;re doing it wrong&#8230;</title>
		<link>http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/</link>
		<comments>http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 11:47:56 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[WTF]]></category>
		<category><![CDATA[Boolean data type]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[C Sharp syntax]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[Data types]]></category>
		<category><![CDATA[Notation]]></category>
		<category><![CDATA[Null]]></category>
		<category><![CDATA[Primitive types]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Software engineering]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=967</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/' addthis:title='PHP Functions, you&#8217;re doing it wrong&#8230; '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Just a quick tip today. If your function looks something like this: &#160; &#60;?php /** * A really long function definition * @param string $has * @param bool $a * @param int $lot * @param float $of * @param assoc_array $parameters * @param string $I * @param string $wonder * @param int $what * @param [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/' addthis:title='PHP Functions, you&#8217;re doing it wrong&#8230; ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/03/documenting-php-code/' rel='bookmark' title='Documenting PHP Code'>Documenting PHP Code</a></li>
<li><a href='http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/' rel='bookmark' title='RE: Top 10 PHP Techniques That Will Save You Time and Effort'>RE: Top 10 PHP Techniques That Will Save You Time and Effort</a></li>
<li><a href='http://blog.seanja.com/2009/07/php-pop-quiz-hotshot/' rel='bookmark' title='PHP Pop Quiz Hotshot'>PHP Pop Quiz Hotshot</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/' addthis:title='PHP Functions, you&#8217;re doing it wrong&#8230; '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Just a quick tip today. If your function looks something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * A really long function definition
 * @param string $has
 * @param bool $a
 * @param int $lot
 * @param float $of
 * @param assoc_array $parameters
 * @param string $I
 * @param string $wonder
 * @param int $what
 * @param int $they
 * @param int $do 
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> myfunction<span style="color: #009900;">&#40;</span>
	<span style="color: #000088;">$has</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$a</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$lot</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$of</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$parameters</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$I</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$wonder</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$what</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> 
	<span style="color: #000088;">$they</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$do</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span>
	<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//do some magic</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//this is how it would be called</span>
myfunction<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color:#800080;">1.2</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'one'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'two'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'I'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You are doing it wrong, if all of these parameters are really nullable and required for your function, and there is no way for you to split it up, then you _can_ refactor it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Quickly refactored to make it easier to use
 * @param array $array containing: (string)'has', (bool)'a', (int)'lot', (float)'of', (assoc_array)'parameters', (string)'I', (string)'wonder', (int)'what', (int)'they', (int)'do'
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> myFunction<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span> <span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//make sure we are only taking in parameters that we recognize...</span>
	<span style="color: #000088;">$has</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'has'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'has'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//array key exists because it is a fake boolean value... it has 3 possibilities</span>
	<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$lot</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lot'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lot'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$of</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'of'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'of'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$parameters</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'parameters'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'parameters'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$I</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'I'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'I'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$wonder</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wonder'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'hwonders'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$what</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'what'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'what'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$they</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'they'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'they'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$do</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'do'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'do'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//some magic</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//it could also be written:</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Quickly refactored to make it easier to use
 * @param array $array containing: (string)'has', (bool)'a', (int)'lot', (float)'of', (assoc_array)'parameters', (string)'I', (string)'wonder', (int)'what', (int)'they', (int)'do'
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> myFunction<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span> <span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//make sure we are only taking in parameters that we recognize...</span>
	<span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'has'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'lot'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'of'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'parameters'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'I'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wonder'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'what'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'they'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'do'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$arg</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$$arg</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$arg</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">//some magic</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">//this is how it would be called</span>
<span style="color: #666666; font-style: italic;">//equivalent to:</span>
<span style="color: #666666; font-style: italic;">//myfunction(null, false, null, 1.2, array('one'=&gt;1, 'two'=&gt;2), 'I', null, 1, null, 3);</span>
myfunction<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'lot'</span><span style="color: #339933;">=&gt;</span><span style="color:#800080;">1.2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'parameters'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'one'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'two'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'I'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'I'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'what'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'do'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>It may be more to type, but it is harder to get it wrong when you are using named parameters. You don&#8217;t have to remember what each of the parameters do in their specific positions either so it is easier to understand the code as you quickly glance at it. Note that this is similar to the way that a lot of ruby functions are written, except we don&#8217;t have a short hand for named parameters like they do (it would be awesome if we did&#8230;):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
myfunction<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:a</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#ff3333; font-weight:bold;">:lot</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1.2</span>, <span style="color:#ff3333; font-weight:bold;">:parameters</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:one</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>, <span style="color:#ff3333; font-weight:bold;">:two</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span> <span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#ff3333; font-weight:bold;">:I</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'I'</span>, <span style="color:#ff3333; font-weight:bold;">:what</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>, :<span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>While this is definitely easier to read and remember, it is probably worth refactoring a function like this (as it is an extreme case) further because it is likely that you are doing way too many things within it.</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/' addthis:title='PHP Functions, you&#8217;re doing it wrong&#8230; ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/03/documenting-php-code/' rel='bookmark' title='Documenting PHP Code'>Documenting PHP Code</a></li>
<li><a href='http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/' rel='bookmark' title='RE: Top 10 PHP Techniques That Will Save You Time and Effort'>RE: Top 10 PHP Techniques That Will Save You Time and Effort</a></li>
<li><a href='http://blog.seanja.com/2009/07/php-pop-quiz-hotshot/' rel='bookmark' title='PHP Pop Quiz Hotshot'>PHP Pop Quiz Hotshot</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>RE: Top 10 PHP Techniques That Will Save You Time and Effort</title>
		<link>http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/</link>
		<comments>http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 00:59:10 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Emergency]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[WTF]]></category>
		<category><![CDATA[$pm_table PM]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[Global variable]]></category>
		<category><![CDATA[mySQL]]></category>
		<category><![CDATA[MySQL AB]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Prime Minister]]></category>
		<category><![CDATA[Procedural programming languages]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Smarty]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Xdebug]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=943</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/' addthis:title='RE: Top 10 PHP Techniques That Will Save You Time and Effort '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>I realise that I already posted something today, but this seemed like an emergency&#8230; I thought maybe this was a serious post when I clicked on it, then when I got to number 2 on the list (I had skipped reading his post about how you should write an index page), I thought maybe he [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/' addthis:title='RE: Top 10 PHP Techniques That Will Save You Time and Effort ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2008/06/dynamic-images-with-php/' rel='bookmark' title='Dynamic Images with PHP'>Dynamic Images with PHP</a></li>
<li><a href='http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/' rel='bookmark' title='PHP Functions, you&#8217;re doing it wrong&#8230;'>PHP Functions, you&#8217;re doing it wrong&#8230;</a></li>
<li><a href='http://blog.seanja.com/2010/03/documenting-php-code/' rel='bookmark' title='Documenting PHP Code'>Documenting PHP Code</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/' addthis:title='RE: Top 10 PHP Techniques That Will Save You Time and Effort '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>I realise that I already posted something today, but this seemed like an emergency&#8230;</p>
<p><img src="http://imgs.xkcd.com/comics/duty_calls.png" alt="What do you want me to do?  LEAVE?  Then they'll keep being wrong!" /></p>
<p>I thought maybe this was a serious post when I clicked on it, then when I got to number 2 on the list (I had skipped reading his post about how you <em>should</em> write an index page), I thought maybe he was joking, but at the end of it I realised that he was not.</p>
<blockquote><p>
<strong>1. How to Properly Create a Website Index Page</strong><br />
See my post about how to do it right.<br />
[... snip]</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'home'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'home'</span><span style="color: #339933;">:</span>           <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'mail'</span><span style="color: #339933;">:</span>           <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'contact'</span><span style="color: #339933;">:</span>        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
        <span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'home'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$page</span>.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>[... snip]
</p></blockquote>
<p>Apparently this is the <em>right</em> way. I do like the single point of entry idea, and at least he is filtering the variables so you can&#8217;t load other php pages right? It really is too bad my $_COOKIE['page'] = &#8216;mail&#8217;&#8230; I wonder what the rest of the site is like. This also makes it a pain to add new pages, and causes a massive switch statement.</p>
<blockquote><p>
<strong>2. Use the Request Global Array to Grab Data</strong><br />
There is actually no reason to use $_GET and $_POST arrays to grab values. $_REQUEST, is another global array that fetches you either a get or form request. Therefore, it’s most times more convenient to use something like this to parse data&#8230;
</p></blockquote>
<p>No! This is wrong, the $_REQUEST array contains not only the $_POST and $_GET variable contents but it also contains the contents of the $_COOKIE array. The arrays are merged in the order described by your php.ini file, generally $_GET, $_POST, $_COOKIE but not always. So, use the $_POST variable when you mean for it to come from the $_POST variable, use the $_GET for get variables, and the $_COOKIE for things in the cookie. Don&#8217;t take the lazy way out.</p>
<blockquote><p>
<strong>3. Debugging PHP is About var_dump</strong><br />
If you’re looking for php debugging techniques, i have to say that var_dump is most times the way to go about it&#8230;
</p></blockquote>
<p>Wrong again. var_dump simply tells you what is in whatever object/array/whatever you are var_dumping. The xdebug extension is a much better alternative:</p>
<p><em><br />
The Xdebug extension helps you debugging your script by providing a lot of valuable debug information. The debug information that Xdebug can provide includes the following:</p>
<p>    * stack traces and function traces in error messages with:<br />
          o full parameter display for user defined functions<br />
          o function name, file name and line indications<br />
          o support for member functions<br />
    * memory allocation<br />
    * protection for infinite recursions</p>
<p>Xdebug also provides:</p>
<p>    * profiling information for PHP scripts<br />
    * code coverage analysis<br />
    * capabilities to debug your scripts interactively with a debug client<br />
</em></p>
<p><a href="http://xdebug.org/">http://xdebug.org/</a></p>
<blockquote><p>
<strong>4. PHP Handles The Code Logic, Smarty Handles The Presentation</strong><br />
&#8230; Learn to use smarty as a template engine for your websites, it will pay off, i promise.
</p></blockquote>
<p>While I am not advocating combining &#8220;Code Logic&#8221; and &#8220;Presentation&#8221;, there are much better tools out there than Smarty. Smarty is a horrid piece of archaic spaghetti that had it&#8217;s purpose a long time ago, but no longer really does. Or you could learn to separate the presentation from the logic by using one of the myriads of frameworks out there. You could even go one better by separating it out to use the MVC pattern.</p>
<blockquote><p>
<strong>5. When You Absolutely Need Global Values, Create a Config File</strong><br />
&#8230; Doing it for database tables or database connection information is a good idea, but do not use global variables throughout your PHP code. Moreover, it is always a better idea to keep your global variables at a single config.php file.
</p></blockquote>
<p>Actually&#8230; this one isn&#8217;t bad, polluting the global namespace is something you should try to avoid, and keeping all of your config values in one place makes them easy to find.</p>
<blockquote><p>
<strong>6. If NOT Defined, Access Denied !</strong><br />
If you’re creating your pages the correct way, there will absolutely no reason for anybody to access any other php page other than index.php or home.php.
</p></blockquote>
<p>This goes back to #1, a horrible way to make an index page.</p>
<blockquote><p>
<strong>7. Create a Database Class</strong><br />
If you’re doing database programming (pretty common in PHP), it would be a very good idea to create a database class to handle any database management functions.
</p></blockquote>
<p>He then goes on to suggest you make a dbExec($query) function which calls $this->db->exec($query), and a sanitize($var1, $var2&#8230;) function which will not actually sanitize the input (it appears to just be making sure the input is numeric?). In his examples he is using the PEAR classes for his database abstraction, which already does this&#8230; so I am not sure what the point of putting a database abstraction ontop of a database abstraction is here. Also, use the escape functions that are already given to you by php (or the pear library so that your code is portable across database backends), <em>do <strong>not</strong> write your own, you <strong>will</strong> get it wrong</em>.</p>
<blockquote><p>
<strong>8. A php File Handles Input, a class.php File Handles Functionality</strong><br />
[...] The php file gets any input that we need and then redirects execution to a function residing to the class file. [...]
</p></blockquote>
<p>It almost seems like he is implementing a poorman&#8217;s MVC? I think? Mostly? A much better way would be to actually use an MVC framework (or to look at a tutorial online and see a much better way to do it).</p>
<blockquote><p>
<strong>9. Know Your SQL and Always Sanitize</strong><br />
Let me present you an example of a function that uses mySQL and sanitazes using the function seen on point #7</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getSentMessages<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">util</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sanitizeInput</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #000088;">$pm_table</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'config'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'privateMsg'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$users</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'config'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'users'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT PM.*, USR.username as name_sender FROM <span style="color: #006699; font-weight: bold;">$pm_table</span> PM, <span style="color: #006699; font-weight: bold;">$users</span> USR
	    WHERE id_sender = '<span style="color: #006699; font-weight: bold;">$id</span>' AND sender_purge = FALSE AND USR.id = PM.id_receiver AND is_read = TRUE
	    ORDER BY date_sent DESC&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbQueryAll</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span></pre></div></div>

</blockquote>
<p>The message is the right one. Sanitize your input. However, it would be awesome if he used some coding standards for naming his variables $user and $pm_table are both tables apparently. The well named function sanitizeInput should probably be renamed to checkInt or something similar since that is what it appears to do. He should also probably not be putting his variables straight in the string, to make it easier to change the query later on when he realises that he missed something. Don&#8217;t even get me started on the fact that this function is private and presumably extends his database abstraction class&#8230;</p>
<blockquote><p>
<strong>10. When You Need Just an Object, Use a Singleton Pattern</strong><br />
It happens pretty often in PHP that we just need a single object created one time and then used globally throughout our whole program. A good example of this is the smarty variable that has to be initialized once and then is used all over the place.<br />
[..snip...]</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> smartyObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'config'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SmartyObj'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$smarty</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SmartyGame<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'config'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SmartyObj'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$smarty</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
        <span style="color: #000088;">$smarty</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'config'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SmartyObj'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$smarty</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>[.../snip...]
</p></blockquote>
<p>The singleton pattern: you&#8217;re doing it wrong.</p>
<p>This is not actually a singleton pattern, while yes it lets you get the instance that you created earlier, you can still create the object by normal means, so I could have $GLOBALS['config']['SmartyObj'], $GLOBALS['config']['SmartyObj2'], $GLOBALS['config']['SmartyObj3'] which would all be instances of the smarty object, but they can all have different properties and values. If it were a singleton this would not be the case. The proper way of doing this is to use the pattern described in the php.net manual under <a href="http://php.net/manual/en/language.oop5.patterns.php#language.oop5.patterns.singleton">Patterns Singleton</a>. That way it is always the same object everywhere that you use it, and you do not have to muck around with the $GLOBALS array (which I am pretty sure is a <a href="http://en.wikipedia.org/wiki/Code_smell">code smell</a>&#8230;).</p>
<p>Read his full post <a href="http://www.codercaste.com/2010/03/28/top-10-php-techniques-that-will-save-you-time-and-effort/comment-page-1/">here</a>. If you think I may have been too harsh, or not harsh enough, on him, leave a comment.</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/' addthis:title='RE: Top 10 PHP Techniques That Will Save You Time and Effort ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2008/06/dynamic-images-with-php/' rel='bookmark' title='Dynamic Images with PHP'>Dynamic Images with PHP</a></li>
<li><a href='http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/' rel='bookmark' title='PHP Functions, you&#8217;re doing it wrong&#8230;'>PHP Functions, you&#8217;re doing it wrong&#8230;</a></li>
<li><a href='http://blog.seanja.com/2010/03/documenting-php-code/' rel='bookmark' title='Documenting PHP Code'>Documenting PHP Code</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>When is 4 &#8211; 1 = 4?</title>
		<link>http://blog.seanja.com/2009/08/when-is-4-1-4/</link>
		<comments>http://blog.seanja.com/2009/08/when-is-4-1-4/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 00:59:07 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[WTF]]></category>
		<category><![CDATA[Chain-of-responsibility pattern]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Software design patterns]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Variable shadowing]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=727</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2009/08/when-is-4-1-4/' addthis:title='When is 4 &#8211; 1 = 4? '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>When c like languages say so $a = 5; $b = 1; &#160; $result = $a---$b; echo $a; #=&#62;4 echo $b; #=&#62;1 echo $result; #=&#62;4 public class FunMaths&#123; public static void main&#40;String&#91;&#93; args&#41; &#123; int result; int a = 5, b = 1; result = a---b; System.out.println&#40;a&#41;; System.out.println&#40;b&#41;; System.out.println&#40;result&#41;; &#125; &#125; Related posts: Orms and [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2009/08/when-is-4-1-4/' addthis:title='When is 4 &#8211; 1 = 4? ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/05/orms-and-circular-references/' rel='bookmark' title='Orms and Circular References'>Orms and Circular References</a></li>
<li><a href='http://blog.seanja.com/2011/07/trollin-oracle/' rel='bookmark' title='Trollin Oracle'>Trollin Oracle</a></li>
<li><a href='http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/' rel='bookmark' title='PHP Functions, you&#8217;re doing it wrong&#8230;'>PHP Functions, you&#8217;re doing it wrong&#8230;</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2009/08/when-is-4-1-4/' addthis:title='When is 4 &#8211; 1 = 4? '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>When c like languages say so</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$a</span><span style="color: #339933;">---</span><span style="color: #000088;">$b</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">#=&gt;4
</span><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$b</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">#=&gt;1
</span><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">#=&gt;4</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FunMaths<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> result<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> a <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span>, b <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		result <span style="color: #339933;">=</span> a<span style="color: #339933;">---</span>b<span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2009/08/when-is-4-1-4/' addthis:title='When is 4 &#8211; 1 = 4? ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/05/orms-and-circular-references/' rel='bookmark' title='Orms and Circular References'>Orms and Circular References</a></li>
<li><a href='http://blog.seanja.com/2011/07/trollin-oracle/' rel='bookmark' title='Trollin Oracle'>Trollin Oracle</a></li>
<li><a href='http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/' rel='bookmark' title='PHP Functions, you&#8217;re doing it wrong&#8230;'>PHP Functions, you&#8217;re doing it wrong&#8230;</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2009/08/when-is-4-1-4/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>On naming functions sanely</title>
		<link>http://blog.seanja.com/2009/05/on-naming-functions-sanely/</link>
		<comments>http://blog.seanja.com/2009/05/on-naming-functions-sanely/#comments</comments>
		<pubDate>Wed, 13 May 2009 23:28:37 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WTF]]></category>
		<category><![CDATA[Actuarial science]]></category>
		<category><![CDATA[Behavior]]></category>
		<category><![CDATA[Ethics]]></category>
		<category><![CDATA[long bug search]]></category>
		<category><![CDATA[Mathematical finance]]></category>
		<category><![CDATA[Philosophy]]></category>
		<category><![CDATA[Value]]></category>
		<category><![CDATA[Value at risk]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=613</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2009/05/on-naming-functions-sanely/' addthis:title='On naming functions sanely '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>When naming your functions, there are certain function prefix/postfixes that should only return specific types. They help the programmers who follow in your footsteps to grasp what it is you were trying to do. It also reduces the number of comments you need because the naming conventions are self explanatory. Here is a short list [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2009/05/on-naming-functions-sanely/' addthis:title='On naming functions sanely ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/' rel='bookmark' title='PHP Functions, you&#8217;re doing it wrong&#8230;'>PHP Functions, you&#8217;re doing it wrong&#8230;</a></li>
<li><a href='http://blog.seanja.com/2008/07/spartan-coding/' rel='bookmark' title='Spartan Coding'>Spartan Coding</a></li>
<li><a href='http://blog.seanja.com/2009/08/a-couple-useful-jquery-snippets/' rel='bookmark' title='A couple useful jQuery Snippets'>A couple useful jQuery Snippets</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2009/05/on-naming-functions-sanely/' addthis:title='On naming functions sanely '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>When naming your functions, there are certain function prefix/postfixes that should only return specific types. They help the programmers who follow in your footsteps to grasp what it is you were trying to do. It also reduces the number of comments you need because the naming conventions are self explanatory. Here is a short list of some of those function modifiers and the expected return values.</p>
<p>The following should only return <strong>boolean</strong> values, they should not set anything in the class. They are <a href="http://en.wikipedia.org/wiki/Idempotence">idempotent</a>. If they are not, you have probably done something wrong or your function is misnamed. Rename it quick before anyone else mistakes it for something that it is not and causes a long bug search.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">is_something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
something_exists<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The following should probably <strong>not return a value</strong> (but if they do it should be true or false based on their success).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">set_something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
unset_something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
import_something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
read_something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
calculate_something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
something_calculation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//this one obviously shouldn't return a value... it could throw an exception though</span>
<span style="color: #000088;">$something</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">var</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$something_else</span><span style="color: #339933;">;</span></pre></div></div>

<p>The following <strong>should only return values</strong> not set them or change anything prior to returning them.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">get_something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
retrieve_something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$something_else</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$something</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">var</span><span style="color: #339933;">;</span>
something_value<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The following <strong>should only return an integer</strong> (long, double&#8230;).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">count_something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
something_count<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The following are similar, they <strong>should also return a number</strong> of some sort (could be a float, an int, a double).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">total_something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
something_total<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
sum_something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Another thing, don&#8217;t use this naming scheme:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">get_something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
get_somethings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>There is not enough difference when you are glancing at them quickly or trying to debug something, or you are scrolling through them in an auto-complete pop-up, or documentation. Rather use this one, it is easier to differentiate.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">get_something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
get_all_somethings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Remember:</p>
<blockquote><p>Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live.</p></blockquote>
<p><a href="http://www.codinghorror.com/blog/archives/001137.html">- C2.com via Coding Horror</a></p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2009/05/on-naming-functions-sanely/' addthis:title='On naming functions sanely ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/' rel='bookmark' title='PHP Functions, you&#8217;re doing it wrong&#8230;'>PHP Functions, you&#8217;re doing it wrong&#8230;</a></li>
<li><a href='http://blog.seanja.com/2008/07/spartan-coding/' rel='bookmark' title='Spartan Coding'>Spartan Coding</a></li>
<li><a href='http://blog.seanja.com/2009/08/a-couple-useful-jquery-snippets/' rel='bookmark' title='A couple useful jQuery Snippets'>A couple useful jQuery Snippets</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2009/05/on-naming-functions-sanely/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Smarty Best Practices 1</title>
		<link>http://blog.seanja.com/2009/05/smarty-best-practices-1/</link>
		<comments>http://blog.seanja.com/2009/05/smarty-best-practices-1/#comments</comments>
		<pubDate>Thu, 07 May 2009 22:28:33 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Smarty]]></category>
		<category><![CDATA[WTF]]></category>
		<category><![CDATA[ado]]></category>
		<category><![CDATA[Template engines]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=598</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2009/05/smarty-best-practices-1/' addthis:title='Smarty Best Practices 1 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>I know I have slagged a lot on smarty in the past, both on my blog and on twitter&#8230; It is not because I do not understand it, it is because I see it being misused (at least as far as I am concerned, I may be wrong about it) every day in old projects [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2009/05/smarty-best-practices-1/' addthis:title='Smarty Best Practices 1 ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2009/04/smarty-again/' rel='bookmark' title='Smarty&#8230; again'>Smarty&#8230; again</a></li>
<li><a href='http://blog.seanja.com/2009/02/templating/' rel='bookmark' title='Templating'>Templating</a></li>
<li><a href='http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/' rel='bookmark' title='RE: Top 10 PHP Techniques That Will Save You Time and Effort'>RE: Top 10 PHP Techniques That Will Save You Time and Effort</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2009/05/smarty-best-practices-1/' addthis:title='Smarty Best Practices 1 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>I know I have slagged a lot on smarty in the past, both on my blog and on twitter&#8230; It is not because I do not understand it, it is because I see it being misused (at least as far as I am concerned, I may be wrong about it) every day in old projects and all over the internet. So, to make up for the slagging that it has received from me, I will now attempt to show you some best practices (or How to use Smarty the smart way). So, without further ado&#8230;</p>
<h3>Rule 1: Don&#8217;t Manipulate the data</h3>
<p>First of all, before you even start using smarty, you have to realise that this is a templating language. You are not supposed to process the data, create new data, delete data, get new data (and so on)&#8230; When you are ready to display your template you should already have the data retrieved/created, and ready to go. If you are considering doing this in your smarty template, stop and take a look at your backend code, you probably did something wrong back there. I guess I should do these as some kind of list, so&#8230;</p>
<p>Sure it is tempting to do:</p>

<div class="wp_syntax"><div class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #D36900;">&#123;</span><span style="color: #008000;">assign</span> var<span style="color: #D36900;">=</span><span style="color: #ff0000;">'newVar'</span> <span style="color: #6A0A0A;">value</span><span style="color: #D36900;">=</span><span style="color: #00aaff;">$oldVar</span>.<span style="color: #006600;">varThatINeed</span><span style="color: #D36900;">&#125;</span></pre></div></div>

<p>But don&#8217;t. It means that people have to go looking for not only $newVar in the php code that displayed the template, they also have to go looking through the smarty code for the assignment. If you need to access that variable, do this instead:</p>

<div class="wp_syntax"><div class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #D36900;">&#123;</span><span style="color: #00aaff;">$oldVar</span>.<span style="color: #006600;">varThatINeed</span><span style="color: #D36900;">&#125;</span></pre></div></div>

<p>If that variable is supposed to get something from an array, do this:</p>

<div class="wp_syntax"><div class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #D36900;">&#123;</span><span style="color: #00aaff;">$arrayVar</span><span style="color: #D36900;">&#91;</span><span style="color: #00aaff;">$oldVar</span>.<span style="color: #006600;">varThatINeed</span><span style="color: #D36900;">&#93;</span><span style="color: #D36900;">&#125;</span></pre></div></div>

<p>Sure it takes a second more to write it out each time, but it is easier to find in the smarty code.</p>
<h4>Breaking Rule 1</h4>
<p>There are times when you might need to break rule one. If you find yourself doing anything more complicated than:</p>

<div class="wp_syntax"><div class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">math</span> equation<span style="color: #D36900;">=</span><span style="color: #ff0000;">&quot;x + y&quot;</span> x<span style="color: #D36900;">=</span><span style="color: #00aaff;">$height</span> y<span style="color: #D36900;">=</span><span style="color: #00aaff;">$width</span><span style="color: #D36900;">&#125;</span></pre></div></div>

<p>in your template, you should take a step back and look at your code again, why are you doing it this way? Should you be doing it this way? Isn&#8217;t there  a better way?<br />
I think that even this example provided by the smarty documentation is probably a bit much for the template, especially if the equation is likely to change:</p>

<div class="wp_syntax"><div class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">{* Calculate something *}</span>
<span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">math</span> equation<span style="color: #D36900;">=</span><span style="color: #ff0000;">&quot;(( x + y ) / z )&quot;</span> x<span style="color: #D36900;">=</span><span style="color: #00aaff;">$vars</span>.<span style="color: #006600;">var1</span> y<span style="color: #D36900;">=</span><span style="color: #00aaff;">$vars</span>.<span style="color: #006600;">var2</span> z<span style="color: #D36900;">=</span><span style="color: #00aaff;">$vars</span>.<span style="color: #006600;">var3</span><span style="color: #D36900;">&#125;</span></pre></div></div>

<p>It should probably be something more like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> calculateSomething<span style="color: #009900;">&#40;</span><span style="color: #000088;">$vars</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #339933;">...</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//notice I don't rename the function so that you can find it easily later on</span>
<span style="color: #666666; font-style: italic;">//if you didn't want your function named this way, name it something else in your php code...</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">register_modifier</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'calculateSomething'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'calculateSomething'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_template.tpl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #D36900;">&#123;</span>vars|@caclulateSomething<span style="color: #D36900;">&#125;</span></pre></div></div>

<p>Notice the @ symbol, this means pass the whole array as one variable. This is important because smarty apply the modifier to each of the variables in the array if you do not (unless that is what you wanted to happen). While in some cases you may need to break the first rule, if you do it this way, it is managable, reusable. An even better way would be to do this before it gets to the template, but it is understandable to no want to go through the data twice, so this seems like a fair trade off as you are still doing the manipulation in php, and displaying the results of the manipulation in smarty.</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2009/05/smarty-best-practices-1/' addthis:title='Smarty Best Practices 1 ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2009/04/smarty-again/' rel='bookmark' title='Smarty&#8230; again'>Smarty&#8230; again</a></li>
<li><a href='http://blog.seanja.com/2009/02/templating/' rel='bookmark' title='Templating'>Templating</a></li>
<li><a href='http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/' rel='bookmark' title='RE: Top 10 PHP Techniques That Will Save You Time and Effort'>RE: Top 10 PHP Techniques That Will Save You Time and Effort</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2009/05/smarty-best-practices-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Smarty&#8230; again</title>
		<link>http://blog.seanja.com/2009/04/smarty-again/</link>
		<comments>http://blog.seanja.com/2009/04/smarty-again/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 02:26:39 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[WTF]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[Data management]]></category>
		<category><![CDATA[Insert]]></category>
		<category><![CDATA[mySQL]]></category>
		<category><![CDATA[MySQL AB]]></category>
		<category><![CDATA[Smarty]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Template engines]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=586</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2009/04/smarty-again/' addthis:title='Smarty&#8230; again '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Smarty again.To those who think that smarty prevents you in any way from writting your business logic into a template&#8230; watch this&#8230; &#160; &#123;php&#125; &#160; if &#40;!$link = mysql_connect&#40;'mysql_host', 'mysql_user', 'mysql_password'&#41;&#41; &#123; echo 'Could not connect to mysql'; exit; &#125; &#160; if &#40;!mysql_select_db&#40;'mysql_dbname', $link&#41;&#41; &#123; echo 'Could not select database'; exit; &#125; &#160; $sql = [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2009/04/smarty-again/' addthis:title='Smarty&#8230; again ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2009/05/smarty-best-practices-1/' rel='bookmark' title='Smarty Best Practices 1'>Smarty Best Practices 1</a></li>
<li><a href='http://blog.seanja.com/2009/02/templating/' rel='bookmark' title='Templating'>Templating</a></li>
<li><a href='http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/' rel='bookmark' title='RE: Top 10 PHP Techniques That Will Save You Time and Effort'>RE: Top 10 PHP Techniques That Will Save You Time and Effort</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2009/04/smarty-again/' addthis:title='Smarty&#8230; again '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Smarty <a title="again" href="http://blog.seanja.com/2009/02/templating/">again</a>.To those who think that smarty prevents you in any way from writting your business logic into a template&#8230; watch this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #009900;">&#123;</span>php<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mysql_host'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mysql_user'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mysql_password'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Could not connect to mysql'</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mysql_dbname'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Could not select database'</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$sql</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&quot;INSERT INTO unsafe_tabel (unsafe_var) VALUES('</span><span style="color: #0000ff;">&quot;.<span style="color: #006699; font-weight: bold;">$_GET</span>['unsafe'].&quot;</span><span style="color: #0000ff;">')&quot;;
&nbsp;
$result = mysql_query($sql, $link);
&nbsp;
if (!$result) {
    echo &quot;DB Error, could not query the database\n&quot;;
    echo '</span><span style="color: #990000;">MySQL</span> Error<span style="color: #339933;">:</span> <span style="color: #0000ff;">' . mysql_error();
    exit;
}
&nbsp;
{/php}</span></pre></div></div>

<p>I think I might have just put stuff that actually belongs in the model into the view&#8230; and unescaped too&#8230; oh dear&#8230; (that would be template for you smarty folks). So, no, smarty does not disuade you from doing it, infact it seems that they encourage it a bit by providing you with the option to do so via the {php} {/php} tags, instead of forcing you to use {rdelim} {ldelim} all throughout your code instead (which would surely discourage most people). If I can do that, the people who&#8217;s site&#8217;s you&#8217;ve written can surely do that too&#8230; and mess up the nice templates that you have made for them (and their databases too). So, please think of another reason to use Smarty, and if you cannot, then why are you using it?</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2009/04/smarty-again/' addthis:title='Smarty&#8230; again ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2009/05/smarty-best-practices-1/' rel='bookmark' title='Smarty Best Practices 1'>Smarty Best Practices 1</a></li>
<li><a href='http://blog.seanja.com/2009/02/templating/' rel='bookmark' title='Templating'>Templating</a></li>
<li><a href='http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/' rel='bookmark' title='RE: Top 10 PHP Techniques That Will Save You Time and Effort'>RE: Top 10 PHP Techniques That Will Save You Time and Effort</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2009/04/smarty-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

