<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>PHP Diva</title>
	<atom:link href="http://phpdiva.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://phpdiva.com</link>
	<description>actually getting paid for being a smartass</description>
	<lastBuildDate>Wed, 07 Sep 2011 17:28:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='phpdiva.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/0505d19346340357b652c88cd60a3db5?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>PHP Diva</title>
		<link>http://phpdiva.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://phpdiva.com/osd.xml" title="PHP Diva" />
	<atom:link rel='hub' href='http://phpdiva.com/?pushpress=hub'/>
		<item>
		<title>So Long and Thanks for all the Fish</title>
		<link>http://phpdiva.com/2011/09/07/so-long-and-thanks-for-all-the-fish/</link>
		<comments>http://phpdiva.com/2011/09/07/so-long-and-thanks-for-all-the-fish/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 17:25:53 +0000</pubDate>
		<dc:creator>phpdiva</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://phpdiva.com/?p=179</guid>
		<description><![CDATA[Well, that was fun. I have pussyfooted around the idea long enough, and have finally decided to take the plunge. I&#8217;m changing my career to yet another male-dominated field (because I&#8217;m secretly a dude), composing, and putting the coding on indefinite hold. I&#8217;m sure the PHP world will survive. The main purpose of this post [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpdiva.com&amp;blog=6177117&amp;post=179&amp;subd=phpdiva&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="attachment_182" class="wp-caption alignnone" style="width: 470px"><a href="http://phpdiva.files.wordpress.com/2011/09/3533742116_9501a9e03b_o.jpg"><img class="size-full wp-image-182" title="Old piano" src="http://phpdiva.files.wordpress.com/2011/09/3533742116_9501a9e03b_o-e1315416250285.jpg?w=460&#038;h=460" alt="" width="460" height="460" /></a><p class="wp-caption-text">Ivories *</p></div>
<p>Well, that was fun. I have pussyfooted around the idea long enough, and have finally decided to take the plunge. I&#8217;m changing my career to yet another male-dominated field (because I&#8217;m secretly a dude), composing, and putting the coding on indefinite hold. I&#8217;m sure the PHP world will survive.</p>
<p>The main purpose of this post is to let peeps know that I am not currently looking for work, and no, I don&#8217;t know of anyone who does. If you have a film scoring project, however, do get in touch with me (phpdiva at gmail) <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><em>* Photo by <a href="http://www.flickr.com/photos/viamoi/" target="_blank">ViaMoi</a></em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpdiva.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpdiva.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpdiva.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpdiva.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpdiva.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpdiva.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpdiva.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpdiva.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpdiva.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpdiva.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpdiva.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpdiva.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpdiva.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpdiva.wordpress.com/179/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpdiva.com&amp;blog=6177117&amp;post=179&amp;subd=phpdiva&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpdiva.com/2011/09/07/so-long-and-thanks-for-all-the-fish/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/77e6f56b8be84add967973c8ec6f7fb5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">phpdiva</media:title>
		</media:content>

		<media:content url="http://phpdiva.files.wordpress.com/2011/09/3533742116_9501a9e03b_o-e1315416250285.jpg" medium="image">
			<media:title type="html">Old piano</media:title>
		</media:content>
	</item>
		<item>
		<title>Curious behavior of SQL aggregate functions</title>
		<link>http://phpdiva.com/2010/01/29/curious-behavior-of-sql-aggregate-functions/</link>
		<comments>http://phpdiva.com/2010/01/29/curious-behavior-of-sql-aggregate-functions/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 20:06:17 +0000</pubDate>
		<dc:creator>phpdiva</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Did You Know]]></category>

		<guid isPermaLink="false">http://phpdiva.com/?p=163</guid>
		<description><![CDATA[Recently I ran into an interesting problem, while using an aggregate function in a SELECT SQL statement. Initially the behavior seems to defy common sense, so I thought I&#8217;d share. Consider this hypothetical database table called &#8220;items&#8221;: My goal was to retrieve all items with the maximum amount in each category.  Naturally, I wrote the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpdiva.com&amp;blog=6177117&amp;post=163&amp;subd=phpdiva&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="attachment_162" class="wp-caption alignnone" style="width: 470px"><a href="http://phpdiva.files.wordpress.com/2010/01/3759170861_92c9801ccf_b.jpg"><img class="size-full wp-image-162" title="Abacus" src="http://phpdiva.files.wordpress.com/2010/01/3759170861_92c9801ccf_b-e1264792633228.jpg?w=460&#038;h=306" alt="Abacus" width="460" height="306" /></a><p class="wp-caption-text">Abacus *</p></div>
<p>Recently I ran into an interesting problem, while using an <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html" target="_blank">aggregate function</a> in a SELECT SQL statement. Initially the behavior seems to defy common sense, so I thought I&#8217;d share.</p>
<p>Consider this hypothetical database table called &#8220;items&#8221;:</p>
<pre class="brush: plain;">
id | category_id | amount | title
-----------------------------------
1  | 1           | 1      | Item 1
2  | 1           | 2      | Item 2
</pre>
<p>My goal was to retrieve all items with the maximum amount in each category.  Naturally, I wrote the following SQL statement:</p>
<pre class="brush: sql;">
SELECT id, MAX(amount) AS amount, title FROM items GROUP BY category_id;
</pre>
<p>The result was definitely unexpected. What I got was:</p>
<pre class="brush: plain;">
id | amount | title
--------------------
1  | 2      | Item 1
</pre>
<p>So I did get the maximum amount, but no matching data from the corresponding row. It appears that MySQL just grabbed the first row in the group and returned it along with the maximum amount. After some searching, this behavior actually makes sense. Just consider what would have to be the result if we had more than one row with the same maximum amount, or if we had both <code>MAX()</code> and <code>MIN()</code> functions in our statement.</p>
<p>There are a couple ways to still accomplish this in a single query:</p>
<p>Option 1:</p>
<pre class="brush: sql;">
SELECT id, amount, title
FROM items AS items1
WHERE amount = (
    SELECT MAX( amount )
    FROM items AS items2
    WHERE items2.category_id = items1.category_id
)
</pre>
<p>Option 2:</p>
<pre class="brush: sql;">
SELECT items1.id, items1.amount, items1.title
FROM items AS items1, (
    SELECT category_id, MAX( amount ) AS amount
    FROM items
    GROUP BY category_id
) AS items2
WHERE items1.category_id = items2.category_id
AND items1.amount = items2.amount
</pre>
<p>I&#8217;m not sure which approach is better. Option 1 seems to be a bit faster and appears to perform less sub-queries, according to <code>EXPLAIN</code>, but that might entirely depend on your database structure and indexes (<a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-index-types.html" target="_blank">MySQL calls them that</a>). I would be happy to hear an explanation of which way is better and why.</p>
<p>In my own application, for the sake of scalability, I decided to keep an additional table with only the highest amounts in each category. I&#8217;m planning to update that &#8220;tally&#8221; table every time an item is added or edited.</p>
<p>Photo by <a href="http://www.flickr.com/photos/cyberdees/3759170861/" target="_blank">cyberdees</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpdiva.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpdiva.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpdiva.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpdiva.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpdiva.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpdiva.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpdiva.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpdiva.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpdiva.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpdiva.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpdiva.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpdiva.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpdiva.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpdiva.wordpress.com/163/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpdiva.com&amp;blog=6177117&amp;post=163&amp;subd=phpdiva&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpdiva.com/2010/01/29/curious-behavior-of-sql-aggregate-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/77e6f56b8be84add967973c8ec6f7fb5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">phpdiva</media:title>
		</media:content>

		<media:content url="http://phpdiva.files.wordpress.com/2010/01/3759170861_92c9801ccf_b-e1264792633228.jpg" medium="image">
			<media:title type="html">Abacus</media:title>
		</media:content>
	</item>
		<item>
		<title>My very first contributed Drupal module and the joys of installing CVS on Mac OS X</title>
		<link>http://phpdiva.com/2010/01/25/my-very-first-contributed-drupal-module-and-the-joys-of-installing-cvs-on-mac-os-x/</link>
		<comments>http://phpdiva.com/2010/01/25/my-very-first-contributed-drupal-module-and-the-joys-of-installing-cvs-on-mac-os-x/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 21:55:23 +0000</pubDate>
		<dc:creator>phpdiva</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CVS]]></category>
		<category><![CDATA[Drupal module]]></category>
		<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://phpdiva.com/?p=155</guid>
		<description><![CDATA[Awhile back I was working on a Drupal project, and needed to disable the default RSS feed of the site. I was slightly surprised to find that there is no admin setting to do this, nor a module to perform this functionality. However I found this issue in Drupal project issue queue, which apparently was [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpdiva.com&amp;blog=6177117&amp;post=155&amp;subd=phpdiva&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Awhile back I was working on a Drupal project, and needed to disable the default RSS feed of the site. I was slightly surprised to find that there is no admin setting to do this, nor a module to perform this functionality. However I found this <a href="http://drupal.org/node/28337" target="_blank">issue</a> in Drupal project issue queue, which apparently was opened in 2005, and, gasp, still wasn&#8217;t implemented into the Drupal core. Now, I&#8217;m not the one to bash Drupal, because to me it&#8217;s still the best PHP open source CMS out there; but even I thought this was a little out of control. Anyway, make of it what you will.</p>
<p>After consulting the <a href="http://api.drupal.org/" target="_blank">Drupal API, </a>I quicky came up with a solution for my site, and posted it as a comment to the issue. That was almost a year ago.</p>
<p>Recently I was checking on my Drupal discussions, and found out that the issue was still open, the fix didn&#8217;t make it into the core for Drupal 6 (<strong>update:</strong> apparently it didn&#8217;t make it into Drupal 7 either), and people were requesting a one click solution to fix this in the mean time. Long story short, I decided this was my opportunity to give back and contribute this as a small module to the Drupal modules collection.</p>
<p>Since I wanted to make the module available on <a href="http://drupal.org/" target="_blank">drupal.org</a>, I had to go through the CVS application process. In case you&#8217;re curious how to go about it, the steps are:</p>
<ol>
<li>Make sure your module is not a duplicate of <a href="http://drupal.org/project" target="_blank">anything else</a> out there. If in doubt, post to the <a href="http://groups.drupal.org/contributed-module-ideas" target="_blank">Contributed module ideas</a> group (<a href="http://groups.drupal.org/node/38728" target="_blank">my posting here</a>).</li>
<li>Create your module, and validate it against the Drupal <a href="http://drupal.org/coding-standards" target="_blank">coding standards.</a></li>
<li>Submit a <a href="http://drupal.org/cvs-application/requirements" target="_blank">CVS application.</a> Make sure to read the instructions thoroughly. <a href="http://drupal.org/node/653700" target="_blank">My application</a> is not a very good example of doing this, since admittedly I was lazy and wanted to get away with the smallest feature set possible, anticipating that people will request new features through the issue queue. That didn&#8217;t go over so well, and I had to rewrite my module to be more full-featured.</li>
<li>Rinse and repeat!</li>
</ol>
<p>After almost two months of rinsing, my application finally got approved, and it was time to give back to the peoples.</p>
<h3>Oh, how I love CVS!</h3>
<p>Again, Drupal, being what it is, is still using CVS for version control. After reading through <a href="http://drupal.org/handbook/cvs" target="_blank">tons of documentation</a> on using CVS, and tagging and branching conventions in Drupal, I was ready to commit. The only problem: <code>"which cvs"</code> on my Mac was staring back at me with a blank command prompt. I was able to install a pretty nice GUI for Mac OS X, <a href="http://www.syntevo.com/smartcvs/index.html" target="_blank">SmartCVS</a>, but really wanted to stick to the command line, since the documentation was very particular on setting the appropriate flags when running CVS commands.</p>
<p>In my search I have found this <a href="http://www.lullabot.com/videocast/install_cvs_mac_osx" target="_blank">very helpful video on Lullabot</a> on installing the command-line CVS on Mac OS X. All I had to do was download the <a href="http://developer.apple.com/tools/xcode/" target="_blank">Apple XCode Tools,</a> and install a small subset of it to get the CVS. To my dismay, I found that the in the 3.x version of the XCode, the &#8220;small subset&#8221; is close to 2Gb, which was a no go.</p>
<h3>Installing command-line CVS on Max OS X</h3>
<p>And finally the solution. In fact, it was very simple. Just download and install <a href="http://www.charlessoft.com/" target="_blank">Pacifist</a>, which is a sort of installation package browser. Browse the XTools installer with it, search for <em>&#8220;CVS&#8221;,</em> and install the parent package which contains the CVS. I think it was called <em>&#8220;DeveloperToolsCLI&#8221;. </em>Bam, you have command-line CVS!</p>
<h3>And without further ado&#8230;</h3>
<p>&#8230;lo and behold: my first contributed Drupal module: <a href="http://drupal.org/project/rss_permissions" target="_blank">RSS Permissions.</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpdiva.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpdiva.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpdiva.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpdiva.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpdiva.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpdiva.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpdiva.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpdiva.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpdiva.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpdiva.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpdiva.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpdiva.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpdiva.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpdiva.wordpress.com/155/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpdiva.com&amp;blog=6177117&amp;post=155&amp;subd=phpdiva&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpdiva.com/2010/01/25/my-very-first-contributed-drupal-module-and-the-joys-of-installing-cvs-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/77e6f56b8be84add967973c8ec6f7fb5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">phpdiva</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;OMG, I&#8217;m Getting A Blank Screen!&#8221;, or how to set error reporting in PHP</title>
		<link>http://phpdiva.com/2010/01/13/how-to-set-error-reporting-in-php/</link>
		<comments>http://phpdiva.com/2010/01/13/how-to-set-error-reporting-in-php/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 02:10:13 +0000</pubDate>
		<dc:creator>phpdiva</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://phpdiva.wordpress.com/?p=101</guid>
		<description><![CDATA[This may seem obvious for experienced developers, but I&#8217;ll say it anyway: turn on your errors during development. 99% of the time, the notorious &#8220;blank screen&#8221; means that you have an error, and it&#8217;s not being displayed. (In the other 1% of the cases, you are not actually outputting anything to screen and I have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpdiva.com&amp;blog=6177117&amp;post=101&amp;subd=phpdiva&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="attachment_121" class="wp-caption alignnone" style="width: 470px"><a href="http://phpdiva.files.wordpress.com/2010/01/1125019024_78380c13721.jpg"><img class="size-full wp-image-121" title="Blank Screen" src="http://phpdiva.files.wordpress.com/2010/01/1125019024_78380c13721-e1263346366251.jpg?w=460&#038;h=268" alt="Blank Screen" width="460" height="268" /></a><p class="wp-caption-text">Blank Screen *</p></div>
<p>This may seem obvious for experienced developers, but I&#8217;ll say it anyway: <strong>turn on your errors during development.</strong> 99% of the time, the notorious &#8220;blank screen&#8221; means that you have an error, and it&#8217;s not being displayed. (In the other 1% of the cases, you are not actually outputting anything to screen and I have no remorse for you.)</p>
<p>There are several ways to set error reporting in PHP, but before I get to that&#8230;</p>
<p class="important"><strong>DISCLAIMER: </strong>While you should display errors on your development sites, you should NEVER display errors on production server, but log them instead. It&#8217;s a huge security issue, since sensitive data IS displayed in the errors, which makes your site vulnerable to attacks.</p>
<p>OK, not that that&#8217;s out of the way, here&#8217;s how you can set PHP error reporting:</p>
<h3>1. PHP Configuration file: php.ini</h3>
<p>Just modify the lines in your php.ini like so:</p>
<pre class="brush: plain;">
error_reporting  =  E_ALL &amp; ~E_NOTICE
display_errors = On
</pre>
<p>The code above will show all errors, except for notices about potential issues and coding standards warnings, on screen. Those funny squiggly things are <a href="http://www.php.net/manual/en/language.operators.bitwise.php" target="new">Bitwise Operators</a>, and you can read the error reporting level above as &#8220;E_ALL and not E_NOTICE&#8221;.</p>
<p>This is one of the most commonly used error reporting levels, but if you really want to follow the best practices, I suggest setting error_reporting level to <code>E_ALL | E_STRICT</code>, which will display all errors, plus make your code &#8220;future-proof&#8221; by pointing out soon-to-be-deprecated items.</p>
<h3>2. Apache: .htaccess &amp; httpd.conf</h3>
<p>If you don&#8217;t have access to your php.ini file, you can create an .htaccess file and place it in the root of your document, or edit the one already there. Just adding these lines to .htaccess will have the same effect as the php.ini method above:</p>
<pre class="brush: plain;">
php_value error_reporting 6135
php_flag display_errors true
</pre>
<p>If you are wondering where the 6135 came from, it&#8217;s the integer representation of <code>E_ALL &amp; ~E_NOTICE</code>. Each of the predefined PHP error level constants has an integer value. And since .htaccess is not processed by PHP, we don&#8217;t have access to constants yet, so we must use integers.</p>
<p>Basically, 6135 is 6143 (E_ALL) &#8211; 8 (E_NOTICE). Check out the rest of <a href="http://www.php.net/manual/en/errorfunc.constants.php" target="new">Predefined Constants</a> and their integer values. You can also quickly figure out the number you need by echoing the desired expression in your PHP script, like so:</p>
<pre class="brush: php;">
echo E_ALL &amp; ~E_NOTICE;
</pre>
<p>One gotcha to this is that integer value of E_ALL has been changing from version to version (with new error levels being included into E_ALL). Incidentally the line of code above will return 30711 in PHP 5.3, as opposed to 6135 in PHP 5.2. So if you want to display all errors and notices possible, just use</p>
<pre class="brush: plain;">
php_value error_reporting -1
</pre>
<p>You also have an option to set these values in httpd.conf, however I am yet to encounter a situation where it would be the best place to set error reporting.</p>
<h3>3. PHP file</h3>
<p>I personally prefer this method to the other two. There are several advantages to it:</p>
<ul>
<li>Sometimes it can be the only way to set error reporting. You don&#8217;t have access to tweaking php.ini or restarting the server, or .htaccess may be disabled on the host.</li>
<li>If you are using some sort of framework with a common front controller or bootstrap, it&#8217;s the best place to put error reporting. It lets you turn errors on and off depending on the environment. As a matter of fact, most MVC frameworks will have this built in already.</li>
<li>You can place the code anywhere in your PHP document, in case you need to quickly debug a single file or area.</li>
</ul>
<p>As you can see, you will use the same constants as in php.ini file.</p>
<pre class="brush: php;">
if (/... some kind of in development flag .../) {
	ini_set('display_errors', TRUE);
}
else {
	ini_set('display_errors', FALSE);
}
error_reporting(E_ALL &amp;amp; ~E_NOTICE);
</pre>
<p>The &#8220;in development&#8221; flag may be something you set in a configuration file, based on the environment.</p>
<p>If you must turn the errors on on production server <strong>temporarily,</strong> there are a couple ways you can do it without displaying them to the whole world. These are to be used only when stuff hits the fan.</p>
<ul>
<li>You can limit them to only your own IP address, using the little trick below. Replace <code>[ my IP ]</code> with your real IP address, which you can get from a site like <a href="http://www.whatismyip.com/" target="_blank">http://www.whatismyip.com/</a>. Just keep in mind that both of these values can be spoofed.</li>
</ul>
<pre class="brush: php;">
if  ($_SERVER['REMOTE_ADDR'] == '[ my IP ]' || $_SERVER['HTTP_X_FORWARDED_FOR'] == '[ my IP ]')  {
	// Turn on error reporting here.
}
</pre>
<ul>
<li>You could also create a page that sets a specific session value, and only display errors based on that session value. In other words, get creative, but don&#8217;t get carried away.</li>
</ul>
<p>There&#8217;s a gotcha here as well. This will NOT report any syntax errors, like a missing semicolon or comma. That&#8217;s because syntax errors happen during the compilation of your file, so it &#8220;breaks&#8221; before it&#8217;s told to report errors, and you will get a blank screen.</p>
<p>The best way around that is to have a single error-free bootstrap file, which will turn on error display and then  include other files (this is the case in most MVC frameworks). Sometimes that&#8217;s not an option, and you have a single file with a syntax error that you are unable to find.  In that case, if you have access to command-line, just run your file from there:</p>
<pre class="brush: plain;">
$ php myfile.php
</pre>
<p>Even though the logic in the file won&#8217;t work, the compiler will report syntax errors. Another option is to copy the file to a server that has error reporting enabled and find your syntax errors that way.</p>
<h3>So, which one to use!?</h3>
<p>So many options&#8230; Like a lot of things in programming, it&#8217;s largely a matter of taste. But here&#8217;s my preference.</p>
<ul>
<li>If you have a dedicated development server, you should use php.ini. Set it and forget it, so to speak.</li>
<li>If your application has a common file, like a front controller or bootstrap, use the PHP method. That way you can easily control error display on the application level, based on environment and other factors.</li>
<li>.htaccess is best if you don&#8217;t have access to php.ini, and you don&#8217;t have a front-controller application.</li>
</ul>
<p>* Photo by <a href="http://www.flickr.com/photos/toasty/1125019024/" target="_blank">toasty</a></p>
<p>** This post is part of <a href="http://phpdiva.wordpress.com/2010/01/13/debugging-php-guerilla-style/" target="_self">Debugging PHP, Guerilla Style</a> series.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpdiva.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpdiva.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpdiva.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpdiva.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpdiva.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpdiva.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpdiva.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpdiva.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpdiva.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpdiva.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpdiva.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpdiva.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpdiva.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpdiva.wordpress.com/101/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpdiva.com&amp;blog=6177117&amp;post=101&amp;subd=phpdiva&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpdiva.com/2010/01/13/how-to-set-error-reporting-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/77e6f56b8be84add967973c8ec6f7fb5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">phpdiva</media:title>
		</media:content>

		<media:content url="http://phpdiva.files.wordpress.com/2010/01/1125019024_78380c13721-e1263346366251.jpg" medium="image">
			<media:title type="html">Blank Screen</media:title>
		</media:content>
	</item>
		<item>
		<title>Debugging PHP, Guerilla Style</title>
		<link>http://phpdiva.com/2010/01/13/debugging-php-guerilla-style/</link>
		<comments>http://phpdiva.com/2010/01/13/debugging-php-guerilla-style/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 02:09:23 +0000</pubDate>
		<dc:creator>phpdiva</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://phpdiva.wordpress.com/?p=94</guid>
		<description><![CDATA[Arguably, one of the most valuable skills in web development is the ability to debug quickly and efficiently. Bugs are an inseparable part of software development, no matter how great the developer is. There are best practices and tools that can bring the number of bugs to a minimum; and if you are writing a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpdiva.com&amp;blog=6177117&amp;post=94&amp;subd=phpdiva&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="attachment_6" class="wp-caption alignnone" style="width: 370px"><img class="size-full wp-image-6" title="A Nasty Bug" src="http://farm1.static.flickr.com/37/97645369_874477f6e7.jpg" alt="A Nasty Bug" width="360" height="500" /><p class="wp-caption-text">A Nasty Bug *</p></div>
<p>Arguably, one of the most valuable skills in web development is the ability to debug quickly and efficiently. Bugs are an inseparable part of software development, no matter how great the developer is. There are best practices and tools that can bring the number of bugs to a minimum; and if you are writing a project from scratch, you have great leverage to control the environment, and implement those best practices. PHP coders these days have a great selection of debugging tools available, such as <a href="http://www.xdebug.org/" target="_blank">Xdebug</a>, and even full-featured IDEs, like <a href="http://www.zend.com/products/studio/" target="_blank">Zend Studio.</a> I think tools like these are fantastic, and everyone should use them!</p>
<p>However, we don&#8217;t always have access to these tools, or ability to control the environment. Sometimes, depending on the nature of the project, we take over someone else&#8217;s code, don&#8217;t have access to servers, or have to use someone else&#8217;s computer with a plain text editor.</p>
<p>So what is debugging guerilla style? I&#8217;m talking about the covert and creative ways of finding the error fast, when you don&#8217;t have many tools to work with. Sometimes the stuff just hits the fan, and you need to dive in and get it fixed. These tactics may not be the Holy Grail of efficient development, but they may be the only ones available in some situations. They have certainly saved my behind on many occasions. Some of them are PHP-centric, while others can help with pretty much any language.</p>
<p>Once I started writing this, I realized it might be too much information for a single post, so I will break this into a series. This collection is as much for my personal reference, as for public use, therefore I welcome any comments, questions or suggestions. The last thing I want to do is put out false information out there.</p>
<p><a href="http://phpdiva.wordpress.com/2010/01/13/how-to-set-error-reporting-in-php" target="_self">Part I: &#8220;OMG, I&#8217;m Getting A Blank Screen!&#8221; or how to set error reporting in PHP.</a></p>
<p>* Photo by <a href="http://www.flickr.com/photos/cibergaita/97645369/" target="_blank">cibergaita</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpdiva.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpdiva.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpdiva.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpdiva.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpdiva.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpdiva.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpdiva.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpdiva.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpdiva.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpdiva.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpdiva.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpdiva.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpdiva.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpdiva.wordpress.com/94/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpdiva.com&amp;blog=6177117&amp;post=94&amp;subd=phpdiva&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpdiva.com/2010/01/13/debugging-php-guerilla-style/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/77e6f56b8be84add967973c8ec6f7fb5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">phpdiva</media:title>
		</media:content>

		<media:content url="http://farm1.static.flickr.com/37/97645369_874477f6e7.jpg" medium="image">
			<media:title type="html">A Nasty Bug</media:title>
		</media:content>
	</item>
		<item>
		<title>Very creative stopmotion holiday card</title>
		<link>http://phpdiva.com/2009/01/30/very-creative-stopmotion-holiday-card/</link>
		<comments>http://phpdiva.com/2009/01/30/very-creative-stopmotion-holiday-card/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 20:35:23 +0000</pubDate>
		<dc:creator>phpdiva</dc:creator>
				<category><![CDATA[Threshold Interactive]]></category>
		<category><![CDATA[advertising]]></category>
		<category><![CDATA[cool]]></category>
		<category><![CDATA[creative]]></category>
		<category><![CDATA[holiday card]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://phpdiva.wordpress.com/?p=42</guid>
		<description><![CDATA[Check out this awesome holiday card from Threshold Interactive.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpdiva.com&amp;blog=6177117&amp;post=42&amp;subd=phpdiva&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Check out this awesome holiday card from <a href="http://www.thresholdinteractive.com">Threshold Interactive.</a></p>
<span style="text-align:center; display: block;"><a href="http://phpdiva.com/2009/01/30/very-creative-stopmotion-holiday-card/"><img src="http://img.youtube.com/vi/wQzARdSPDBg/2.jpg" alt="" /></a></span>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpdiva.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpdiva.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpdiva.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpdiva.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpdiva.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpdiva.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpdiva.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpdiva.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpdiva.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpdiva.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpdiva.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpdiva.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpdiva.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpdiva.wordpress.com/42/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpdiva.com&amp;blog=6177117&amp;post=42&amp;subd=phpdiva&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpdiva.com/2009/01/30/very-creative-stopmotion-holiday-card/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/77e6f56b8be84add967973c8ec6f7fb5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">phpdiva</media:title>
		</media:content>
	</item>
	</channel>
</rss>
