Which way is better?

While going though some code in a plugin (not one I wrote), I came across the following snippet:

if ( !isset($update_transient->checked) ) return $update_transient;
	else $themes = $update_transient->checked;

Looking at this makes me cringe. Here’s how I would write this:

if (!isset($update_transient->checked))
   return $update_transient;

$themes = $update_transient->checked;

There is no need for the else statement. If the condition is true, an early exit will occur. Otherwise we always want the $themes variable to be updated.

In my opinion, my version is much easier to read. But I’d like to know what the PHP community thinks.

Please feel free to comment and share your thoughts on this.

2014: A look back

So here we are on the eve of a new year. 2014 has been a good one for me. I decided to look back over my posts for the year, and discovered that I only posted 10 times in 2014!  Down from 18 in 2013. This could be because when I started my blog in 2013, there was a lot more learning going on, since I had just switched to PHP. However, I have learned a lot this year as well. Apparently, just not as much as last year. Or, I just got lazy with recording what I learned.

2015 will be an interesting year. We’ll be launching a new site at work, done completely in WordPress. I look forward to seeing what new knowledge I’ll record in the upcoming months.

I wish everyone a happy and prosperous New Year!