Zen Coding

When I first heard of Zen Coding on Sitepoint, I figured it was some other gimmick that might save me about 0.01% of my time each year after I spend five or six hours learning the syntax.

Zen Coding works by expanding some abbreviations into properly closed html. The syntax is very simple, and can be easily explained in just a few examples. The syntax is basically CSS selectors which most web designers / web developers should already know.

Overall, I found installing and using Zen Coding to be very worthwhile. I just made sure to change the shortcut key in Notepad++ because Ctrl + E wasn’t doing it for me. :)

Ports exist for a lot of different editors, and IDEs, so check it out. What other productivity tools do you use?

PEAR Mail – Checking If Mail Sent

PEAR Mail & mail_mime is absolutely fantastic for sending multi-part mime emails and requires absolutely no effort. Probably, the best part of PEAR Mail & mail_mime is not having to deal with mime boundaries.

I often see incorrect code for handling whether the message successfully sent or not. To check if the message is sent we should do something like the following.

$isSent = $mail->send(...);
if (PEAR::isError($isSent)) {
// error handling goes here
} else {
// successfully sent code goes here.
}

If we simply use the following code, we’ll always have a true condition because $isSent won’t be set to null.

$isSent = $mail->send(...);
if ($isSent) {
// successfully sent code goes here.
//Unfortunately this will always be called
} else {
//code here will never actually be executed.
}

Hope this helps!

PHP Object/Variable Life Time

I’m hoping to use this post as a way of clarifying the lifetime of an object in PHP because I am continually running into webdesigners and programmers that don’t understand the lifetime.

To simplify, in PHP between requests only the variables in the contents of $_SESSION are retained. This means that whenever a script executes objects and variables are created and upon completion all objects/variables are destroyed. Many programmers that have programmed in more traditional object oriented languages like C# or Java often build extensive object hierarchies that will be rebuilt on every request unless stored in $_SESSION, cookies, or some other external store.

Unfortunately, many of the patterns and refactorings suggested by the Gang of Four have to be used with caution in PHP because of the stateless nature. The stateless nature of PHP does allow us a lot of extensibility though and allows for much greater scalability.

Learning Drupal

For the last couple of weeks, I have began playing around with Drupal because I’m so sick of fighting proprietary CMS. The proprietary CMS suffers from the vendor updating only updating the CMS when convenient for them and this ends up holding the purchaser hostage. Rolling your own CMS is a terrible idea when there are at least 100s of other CMS that often include 100s of plugins that can perform a lot of the needed functionality.

So far, I haven’t really found anything negative with Drupal’s community or documentation. I am very impressed with the Drupal Handbook and so far have found it sufficient for most of my needs. Drupal doesn’t seem to really suffer from a lack of documentation found in open source software or seem to have any large splits in the community.

So far, I really only have two major complaints or issues with Drupal and both are really more of my fault than anybody else’s. I haven’t exactly found documentation or examples on how to migrate from a different CMS or WordPress: I’m hoping to move away from using a separate templating engine and a separate WordPress blog and combining them in a single instance of Drupal. Migrating completely to one system should allow me to have a single website instead of two distinct entities that only share a domain name: I never really planned to ever have a blog and sort of just bolted it on in hopes of doing something later on.

Drupal’s core is extremely well documented if you happen to start reading the documentation first. I sort of just glanced over the documentation quickly after I did my first install and started tinkering, adding modules, modifying settings, etc. I always seem to learn best by doing. My learning by doing always results in me heading into completely unknown territory and potentially damaging things that already work but again this really helps me to learn a lot about how the software or code performs. I was a little disappointed about the structure of drupal’s core being in multiple “root” folders and thought it would have made more sense to be in a folder like /core to discourage programmers to modify the files. Immediately, I started dropping modules I wanted to use in /module and only realized after reading a little more about the core that modules shouldn’t just be added to /modules and instead should be added to /sites/SITENAMEHERE/modules

Overall, I know that drupal has enough of the functionality that I need in modules and the core to significantly improve the efficiency of my programming and possibly offer a large learning opportunity on software architecture.

PHP Update Finally Depreciates PHP MSSQL driver

A couple of weeks ago, I noticed there was a new version of PHP out than I was using for my development environment (WAMP) and decided that I should take the time and upgrade the development environment and perhaps even the production environment after retesting my web applications.

The actual upgrade process itself was simple, but PHP 5.3 deprecates the MSSQL Extension. Instead you must now use at least the SQL Server Driver for PHP v1.1 which is of course Windows only and requires any installation of Windows preceding Windows 2000. You need to ensure you have installed the SQL Server 2008 Native Client. Making the change wasn’t overly difficult because I took the upfront time and wrote a very simple Database Access Layer because I assumed something may change in the future (driver, database, etc.)

The biggest advantage of the change is being able to better take advantage of Microsoft SQL Server features that probably made you choose to use SQL Server in the first place.In addition, Microsoft has made the source code available. I’m really excited to hear a new version will be out soon that will allow PHP programmers to use PHP Data Objects (PDO) with SQL Server!

Installing PHPUnit on WAMPServer

Test Driven Development and xUnit seem to be popular among many of the professional and very public programmers, so I thought I might like to give it a whirl and see if I can improve the flexibility of my source code and better decouple objects. Unfortunately, I use WAMPServer on Windows as a development server while at work so directions for installing PHP related plugins/PEAR aren’t exactly identical. (Usually, I can figure it out fairly quickly.)

Installing WAMPServer is fairly quick and well documented online, so I won’t cover it specifically although I will mention I am using WAMPServer v2 at time of this writing. I will also assume that you have used the default file paths of “C:wamp” and “C:wampwww”

Steps to installing PHPUnit:

  1. Install PEAR if you haven’t already by opening up a new command window and entering the following commands

    cd wampbinphpphp5.3.0
    go-pear.bat
  2. Press enter when the list of directories appears
  3. When asked if you want PHP.ini to be modified press Y and then enter.
  4. You will be told the include path is updated. Press enter.
  5. You be will be told PEAR_ENV.reg has been created.
    PEAR_ENV.reg
  6. Pear is installed, but it isn’t the newest version of the updater, so we should update because PHPUnit requires at least PEAR Updater 1.8.1
    pear update-channels
  7. Thankfully, we are nearly done our journey. We simply need to add a channel to PEAR and then we can install!
    pear channel-discover pear.phpunit.de
    pear install –alldeps phpunit/PHPUnit

Good luck testing and keep checking back to see how to test!

Website Compatibility Testing (Chrome,IE,FireFox,Opera)

When dealing with clients, prospects, or even employers I won’t generally mention specific browsers that I test my websites in and haven’t really had the question come up much. I honestly would prefer my clients / employeers spend money on something else rather than achieving perfect pixel positioning in every browser, but if they want to achieve this than I won’t complain too much! :-)

For the most part, Chrome, Firefox, and Opera are extremely similar in their rendering ( ~ 100% standards compliance and often have implemented a lot of the draft recommendations) on Windows and seem to be only slightly different at rendering from their respective Windows version on Linux and Macs.

Google Chrome
I haven’t had many occasions where Firefox has rendered differently than Chrome or Chrome has rendered differently than Opera. I usually just install the latest version on a VM for Vista, and Windows XP and haven’t really worried about the old versions as they have rendered almost identically.

Internet Explorer
Normally, you are unable to have multiple versions of Internet Explorer installed on the same operating system. When you upgrade Internet Explorer from 6 to 7 or from 7 to 8 even, most of the actual updates are occuring in the Windows folder.

A very clever individual discovered there was a method of getting multiple versions of IE (multi_ie) working side by side, unfortunately, this doesn’t seem to work any more in XP SP3, or in Windows Vista which i am stuck using at times.

Surprisingly, I found out that Microsoft offers the Internet Explorer Application Compatibility VPC Images which is a group of virtual harddrives created for Microsoft Virtual PC. There’s a whole selection of machine which include: IE6, IE7 (for Vista and XP), IE8 (for Vista and XP) which will definitely help me in my testing and I hope that you will find it helpful too.

Mozilla Firefox
Firefox is extremely strong in standards compliance and seems to account for about 20% of the internet browsers in use especially outside of business. Finding and installing old versions of Firefox isn’t overly difficult, although I do use oldapps.com for versions of browsers and have done very well so far. Typically, I use .0 and .5 releases of Firefox for testing as there’s almost no way I could realistically evaluate my websites in every version of the browser and I haven’t found there to be too many differences in minor releases.

Webdevelopers have a couple of options for testing with Firefox, we can use the standalone / portable ones or install multiple versions instead of using several virtual machines.Installing multiple versions of Firefox is actually fairly easy, as long as you follow the directions: multiple versions of firefox

Opera
Opera has always sort of been an interesting browser as it outlasted Netscape even though it also fought through the browser wars. Opera also used to be shareware and is now free for the PC. Opera is probably one of the better browsers out there as it is sleek, quick, standards compliant, and has some of the better multiple tab handling. Unless asked directly about, I don’t make it a habit of testing in Opera even though I personally enjoy the browser.

Open Source Week 2009

I am so excited to say that I finally booked everything I need to attend the Toronto Open Source Week. In a couple of weeks time, I will be spending a couple of days in Toronto while attending the many conferences, workshops and presentations on open source software (GNU Linux, PHP, etc.)

I am hoping to do some serious networking for my consulting business, along with getting more experience with web programming and the rest of the LAMP stack which seem to be creating an IT revolution.

I hope to see you at some of the events!

Slider by webdesign