PHP Archive

PHP|Tek 2011 TDD Code

Posted 5/31/2011 By Jason

Thank you to everyone who attended my May 25th PHP|Tek talk on Test Driven Development. If you have not had a chance, please do leave feedback on joind.in.

Per the audiance request, below are the requirements, test file and source code we developed during the live tutorial.

Requirements:
Hash object
get and set function
respond to array access

Tests:

<?php

require 'simpletest/autorun.php';
require 'hash.php';

class TekTDDUnitTestCase extends UnitTestCase {
    protected $subject;
    function setup() {
        $this->subject = new Hash;
    }

    function testClassExists() {
        $this->assertTrue(class_exists('Hash'),'Hash Class does not exist');
    }
    
    function testSetMethod() {
            $this->assertNull($this->subject->set('key','value'));
    }
    function testGetMethod() {
            $key = 'foo';
            $value = 'bar'.rand(0,100);
            
            $this->subject->set($key,$value);
            $this->assertEqual     ($value, $this->subject->get($key));
    }
    function testAccessAsAnArray() {
            $key = 'foo';
            $value = 'bar'.rand(0,100);
            
            $this->subject[$key] =$value;
            $this->assertEqual($value, $this->subject[$key]);
        
    }
}

?>

hash.php

<?php

class Hash implements ArrayAccess {
    protected $store = array();
    function offsetExists($key) {
    }
    function offsetGet($key) {
        return $this->get($key);
    }
    function offsetSet($key,$value) {
        $this->set($key, $value);
    }
    function offsetUnset($key) {
    }
    function set($key, $value) {
        $this->store[$key] = $value;
    }
    function get($key) {
        return $this->store[$key];
    }
}

?>

Ideas of March

Posted 3/20/2011 By Jason

One of the things I love about Twitter is it enables me to stay in contact with the PHP community, and in particular the group of speaker I have come to know through PHP conferences. My friend Chris Shiflett tweeted about the “Ideas of March” calling for a revival of the blog as a form of communication for our community.

I am not sure I was ever a good contributor in this form. Jeff Moore always said his aggregator listed me as a “dinosaur” from the frequency of my posts. I stayed at home with my kids this week for spring break, and one thing I accomplished during this time was the migration of my home web and email servers to Rackspace and upgrading the software for this blog to something not as security ridden as what it had been.

As far as Twitter killing the Blogosphere, probably the story of it’s demise is greatly exaggerated. My personal blog revival will not be noticed in a sea of noise, but none the less, hopefully you can stay tuned for more updates with a bit more thought put into them than a tweet or a facebook status update in the future.

CodeWorks

Posted 9/29/2009 By Jason

I am winding down my “tour of duty” with the MTA crew for CodeWorks 2009. This is a really ambitious adventure, seven cities in two weeks. I was a member of the A-Team, doing 3 hour long tutorials on the first day of each city, while the B-Team was arriving. The following day, we would travel to the next city while the B-Team gave 1 hour long presentations. While some folks are signed up for the entire ordeal, I was only able to arrange for one week off, and therefore I am getting off of the train after Dallas.

My presentations were on the topic of Test Driven Development. In an attempt to make the material more interesting and useful for attendees, much of the talk is actually done with live coding. The idea is that after a brief introduction to unit testing, sitting through a simple but reasonably complete example of Test Driven Development for 45 minutes, I can then return to the presentation material and the ideas presented and potential benefits will be more tangible and accessible having had the hands on experience.

This is a copy of the presentation as it was presented in Dallas, and here is a zip file containing all of the live coding examples from all three sessions. I would really appreciate feedback from anyone who attended. Please feel free to tweet, comment on this blog, or use joind.in. If you visit this page there are links to each of the conferences and presentations for you to leave comments. Your feed back for any author is very valuable, to allow us to make any changes to make these talks more useful to audiences in the future.

The format of the trip allowed for much less “hallway track” time, at least for me on the tutorial day crew. I had a wonderful time catching up with my many PHP friends, and some new ones from among the many faces of the conference attendees. If you are attending these conferences, I highly encourage you to hang around with the speakers during the social events. You may learn as much during these times as you do attending the talks, though perhaps not on as focused of a topic. We had some great times, accompanied by good food and drink.

I got a fair dose of humility as well. I discovered it actually matters which airport in Dallas you book your return flight home from. (Note to self: next time book the return flight at the airport next to the hotel.) The upside of that little adventure was I was able to attend the the Microsoft sponsored social event hosted by Josh Holmes, who did a great job interacting with the community during our Dallas stop on the conference tour. After they departed we had a few beers, but no bottle opener. As I was attempting to open it by popping the edge of the cap on the table, from twenty feet away the server let me know “Dude, it’s a twist off”. Ah, live and learn.

Another great PHP conference in the books, now back to the grind stone.

Reflections on php|tek 2009

Posted 6/17/2009 By Jason

Ok, I know I am a little late on this, but I did want to post some thoughts on php|tek 2009.

I was very pleased to be a speaker again this year. On reflection one night, I realized I have been at every “tek” conference as a speaker: php|cruise, php|tropics, php|tek in Orlando and all three of the php|tek Chicago conferences. I am especially pleased because it almost did not happen this year. I had just accepted a job offer at the time the call for papers was taking place. As it ended up, I secured permission from my prospective employer one month prior to my actual start date with them and ended up submitting and presenting my Design Patterns in PHP talk.

Travel for me is just a short 2.5 hour drive from Iowa to Chicago. Two weeks before the conference took place, work decided to hold a carrier conference in Chicago, the speaker for the technical track was unable to attend, and I was asked to fill that role. This took place on Tuesday morning, so I was unable to attend the morning tutorial session. After my work speaking engagement ended, I headed back to the php|tek hotel and attended the afternoon tutorial “PHP Code Review” by Stefan Priebsch, Sebastian Bergmann and Arne Blankerts. These three experts (the co-founders of the php consultancy phpCC) held a code review session citing common example they find in reviews with companies who hire them. Unfortunately, they could not show their clients specific code, so they used examples from popular open source projects. One could characterize this as a “rip on other people’s projects” session, but I don’t think this is a fair assessment. Hopefully any project cited can take this as a bit of free consulting, and remember that while this is obviously not the best location to have a spotlight shined on your code, code bases are evolving organisms, and there were probably descent reasons why the code was structured that way originally. Code can continue to evolve as well, and this kind of a review might just be the impetus which prompts maintainers to refactor away from the problems pointed out in the session. I personally learned a new Design Anti-Pattern in this presentation (and actually referenced it in my own talk later in the week) the Prophet pattern.

I just realized if I covered every talk I went to through the week, this post would go on forever. Suffice to say, there were many great presenters there, and many time slots where I was forced to choose between multiple presentations I wanted to attend. I would be remiss if I did not point out I gave my own talk: “Design Patterns in PHP”, and here are the slides.

Some of the best parts of the conference happen outside of the presentations, and php|tek 2009 was no exception. One aspect of these conferences I have seen getting better every time is the interaction between the regular speakers and the participants in the conference. I think perhaps the greater accessibility of people through mediums like twitter make people want to meet people even more in person, and contributes to longer and more impactful interactions when people do meet in person. During one of the social events, I spoke with Ed Finkler and he told me that he had read my Design Patterns book, and that I had successfully made the whole concept of Design Patterns less academic and more accessible. This was perhaps the most rewarding comment I have had regarding the book, as it validated for me all the work I put into it; the book had the desired impact on a person whom I respect in the coding community.

One of my favorite stories from this conference was about two attendees of the php|tropics conference. I had several interactions with these two attendees during the conference. Both of them have since changed jobs, become more influential in the PHP community, and both of them were speakers during php|tek 2009! One of them is Matthew Weier O’Phinney, now leading the development of the Zend Framework for Zend, and the other was Paul M. Jones, of Solar fame, who had to put up with me on the whole flight back from Cancun to Memphis. It was so much fun to renew my friendships with these people who are now bona fide experts in the field!

One more personal story about PHP community friendships. I met Travis Swicegood online through our work on the SimpleTest project, last year we met in person at php|tek 2008. We stay connected through the wonders of social media, and I saw a tweet from him shortly after he left his job that he needed a room for the conference. I volunteered my rooms couch, and while we caught up, he gave me some great feedback on my presentation, including inspiring me to complete the “Developers Prayer.”

I love attending PHP conferences to renew friendships, to learn, and to be inspired by the creativity in the air. If you have not attended a conference, I invite you to make an effort to attend. Never underestimate the value of networking during these events; when else do you have the chance to rub elbows with (or buy a beer for) the people who wrote the language you make a living from, or who are authors or contributors to the open source projects you use every day. There is tons to learn, and many friendships to be forged. I hope to see you at php|tek 2010!

Seven Things

Posted 1/4/2009 By Jason

Thanks to Brian Deshong I have been tagged with the “Seven Things” meme.

  1. I was born about 5 miles (and one state over) from where I now live, but I moved to Colorado Springs when I was one year old and I consider myself “from” Colorado.
  2. I first learned to program in BASIC, so I could figure out how to cheat on games we loaded from cassette tape on Apple II computers.
  3. My father was once featured in a magazine ad for Apple. He was a junion high school teacher, paid for 1/2 of the first Apple computer purchased in the school district, and they took the picture for the ad in his classroom. They touched up his teeth in the photo, he always claimed that was the cheapest and least painful dental work he ever had.
  4. My mother noticed both of my children are “eve” babies. Caleb was born on Christmas Eve, and Madeline was born on Ground Hogs Day Eve.
  5. I normally do about 8 to 10 hours or martial arts for exercise each week, including Taekwondo, Hapkido, Brazilian Jiu-Jitsu and Kickboxing. I practice Taekwondo with Grand Master Chung E. Kim, and I practice Jiu-Jitsu with Rodrigo Uzeda at Miletich Fighting Systems in Bettendorf.
  6. Don’t tell any PHP zelots, but I actually like the Ruby syntax. Have not done anything substancial with Rails though, more small cgi and shell scripting projects with Ruby.
  7. When I was in college, I was in a group called the Society for Creative Anachronism which recreated the middle ages. There I was know as Lord Karl Wolfgerson, and I was the first Protector of the Barony of Unserhaven.

I would like to tag:

Travis Swicegood,
Jacob Taylor,
Dana Coffey,
Marcus Baker,
Harry Fuecks,
Jeff Moore, and
Dr. Horrible

Oh, and the rules: Mention the person who tagged you, post seven things people might not know about you, then tag seven more people and let them know via post to their blog or mention on twitter.

Changes Afoot

Posted 1/2/2009 By Jason

This morning I turned in my resignation as the “Manager of eBusiness and Commercial Systems” for Alcoa after nine and a half years with the company. Starting January 20th, I will be the “Manager of Implementation and Continuous Improvement” for the World Wide Logistics division of a large agricultural equipment manufacturer headquartered here in Moline Illinois.

My time with Alcoa has been filled with good opportunities, experiences and people. My first big project at Alcoa was the deployment of a Siebel Customer Relationship Management system, and for the rest of my career there, I have been involved in with the IT systems for the Commercial Organization. I was able to put into place a number of other systems, including Linux web servers for PHP based intranet applications, and we put into place a governance process to help ensure the projects we were working on were the most valuable to the organization. I met a number of good people along the way, and build a unique work environment for my immediate work group. I will miss working with everyone as I move on to my new opportunity.

I am really looking forward to my new direction. My immediate work will focus on working with a database of logistics data. There is quite a bit of dimensionality to this data, as it comes from all of the divisions, both inbound and outbound transportation, and import and exports, and various logistics providers as data sources. My team will also work on business process improvement projects in addition to the data related work. I believe my technical background will be very valuable to move these projects along quickly and bring significant value to John Deere in the short term.

Longer term, I am excited about the demographics as well. I will be working at the world headquarters, so there will likely be significant possibilities for advancement without requiring relocation. So far I have been impressed by the leadership and strategy I have been exposed to thus far.

Probably the biggest open question for me on the technical side will be how PHP fits into my new role. For the past year I have been doing some side consulting work for one of the third party logistics providers, creating a dashboard from a subset of the logistics data I will now be responsible for. They are very pleased with the result, but we need to determine how this might fit into the environment and longer term directions overall. Continuing this work as consulting would be a conflict of interest, fortunately I have located a very good person to turn this work over to. On the other hand, after I become acclimated to my new work, I will probably have to start the search for a good replacement for this consulting work. I suspect this role will be even less technical than my current role, so I may come to depend more on the consulting work to keep my technical skills exercised.

I found the decision process regarding this change interesting. I was not being overly aggressive about searching for new employment; I do enjoy my job and the people I work with at Alcoa. I had contacts inside of John Deere with whom I have networks who encouraged me to apply for various positions, and they have a reasonably automated means of notifying you about new positions through their external career web site. Early this fall I was approached by a head hunter on a cold call about doing some CRM work at a director level in another industrial manufacturing company. This caused me to give thought to exactly what I would like to be doing and where I should be headed with my career. It actually prompted me to respond to some friend’s inquiry regarding a PHP position which led to one of the hardest decisions I have made in a long time: declining essentially my dream technical job. Unfortunately, I didn’t have the support of my wife and the economy had just took its’ big nosedive, and would have made it potentially very uncomfortable to relocate. I interviewed for this opportunity shortly after that, but it took several months to actually materialize.

Now onward and upwards! Big changes afoot and it will be exciting to see where they lead me. Happy new year to everyone, I hope your year is filled with excitement and changes as mine is.

php|tek TDD live code

Posted 5/15/2007 By Jason

Many thanks to everyone who attended my Test Driven Development tutorial today at php|tek in Chicago. As promised, here is the code we developed during the live coding sections of the tutorial.

The slides I presented are available from the php|tek site here.

Our first example was a simple Hash object. The requirements we developed for the hash were:
***Hash to repond to get(key) and set(key, value)
***Hash to have isValid(key)
***load from associative array at construction
access via object notation $hash->key or $hash->key = value
***access via array notation $hash[key] or $hash[key] = value

During our session, we covered 4 out of the 5 requirements using TDD.

Here was the test case we ended up with for our Hash object:

<?php

class HashTestCase extends BaseTestCase {
    function testClass() {
        $this->assertTrue(class_exists('Hash'));
    }
    
    function testGetAndSet() {
        $hash = new Hash;
        $this->assertMethodExists($hash, 'get');
        $this->assertMethodExists($hash, 'set');
        
        $hash->set('foo', 'bar');
        $this->assertEqual('bar', $hash->get('foo'));
        $hash->set('baz', 'blah');
        $this->assertEqual('blah', $hash->get('baz'));
    }
    
    function testIsValid() {
        $hash = new Hash;
        $this->assertMethodExists($hash, 'isValid');
        
        $this->assertFalse($hash->isValid('foo'));
        $hash->set('foo', 'bar');
        $this->assertTrue($hash->isValid('foo'));
    }

    function testLoadDuringConstruction() {
        $arr = array('foo' => 'bar');
        $hash = new Hash($arr);
        
        $this->assertEqual('bar', $hash->get('foo'));
        
        $hash2 = new Hash('false');
        $hash2->set('foo','bar');
        $this->assertEqual('bar', $hash2->get('foo'));
    }
    
    function testAccessAsArray() {
        $hash = new Hash(array('foo' => 'bar'));
        $this->assertEqual('bar', $hash['foo']);
    }

}

?>

The code we developed for the Hash class was:

<?php

class Hash implements ArrayAccess {
    function __construct($vals = false) {
        $this->vals = (is_array($vals)) ? $vals : array();
    }
    protected $vals = array();
    function get($key) {
        return $this->vals[$key];
    }
    function set($key, $value) {
        $this->vals[$key] = $value;
    }
    function isValid($key) {
        return array_key_exists($key, $this->vals);
    }
    // functions to implement ArrayAccess
    function offsetExists($key) {
        return $this->isValid($key);
    }
    function offsetGet($key) {
        return $this->get($key);
    }
    function offsetSet($key, $val) {
        $this->set($key, $val);
    }
    function offsetUnset($key) {
        unset($this->vals[$key]);
    }
}

?>

After we reviewed more of the benefits of using TDD, we move on to a more meaty application: a guest book. Here was the test cases we developed:

<?php

class BaseTestCase extends UnitTestCase {
    function assertMethodExists($object, $method) {
        $this->assertTrue(method_exists($object, $method), get_class($object).' object has '.$method.' method');
    }
}

class ModelTestCase extends BaseTestCase {
    function testClass() {
        $this->assertTrue(class_exists('Guestbook'), 'Guestbook class exists');
    }
    
    function testSetDb() {
        $model = new Guestbook;
        $this->assertMethodExists($model, 'setDb');
    }
    
    function testGetComments() {
        $model = new Guestbook;
        $this->assertMethodExists($model, 'getComments');
        
        $this->assertIsA($comments = $model->getComments(), 'array'
            , 'Guestbook::getComments() returns an array [%s]');
        $this->assertTrue(count($comments)>1, 'returned more than one comment');
        $this->assertGreaterThan(
            $comments[0]['created']
            ,$comments[1]['created']
            );
            
    }
    
    function testGetCommentQueryDatabaseWithOrderByClause() {
        $model = new Guestbook;
        $db = new Mockadodb_mysql;
        $db->expectOnce('getArray', array(new WantedPatternExpectation('/order\s+by\screated\s+desc\s*$/i')));
        $model->setDb($db);
        $model->getComments();
    }
    
    function assertGreaterThan($val1, $val2) {
        $this->assertTrue($val1 > $val2, $val1.' is greater than '.$val2);
    }
}

class DbTestCase extends BaseTestCase {
    function testDbConnection() {
        $this->assertIsA($db = DB::conn(), 'adodb_mysql');
        $this->assertMethodExists($db, 'getArray');
    }
    function testAccessToGuestbookTable() {
        $db = DB::conn();
        $this->assertIsA($rs = $db->getArray('select * from Guestbook'), 'array');
        $this->assertTrue(count($rs) > 1, 'result contains more than one row');
        $expected_keys = array('name','comment','created');
        foreach(array_keys($rs[0]) as $key) {
            $this->assertTrue(in_array($key,$expected_keys), $key.' was not expected');
        }
    }
}


class PageTestCase extends WebTestCase {
    protected $url='http://gentoo/~sweatje/conf/phpt_tdd/live/guestbook.php';
    function testPage() {
        $this->get($this->url);
        $this->assertNoUnwantedPattern('/fatal error/i');
        $this->assertTitle('Live Guestbook');
        $this->assertWantedPattern(
            '~
            (<h2>\s*.*?</h2>.*?\w+.*?.*){2,}
            ~imsx');
    }
    function testInputForm() {
        $this->get($this->url);
        $this->assertFieldByName('name');
        $this->assertFieldByName('comment');
    }
}


With these test cases, we developed:

db.php:


?>
<?php

require_once 'adodb/adodb.inc.php';

class DB {
        //static class, we do not need a constructor
        private function __construct() {}

        public static function conn() {
                static $conn;
                if (!$conn) {
                        $conn = adoNewConnection('mysql');
                        $conn->connect('localhost', 'phpauser', 'phpapass', 'phpa');
                        $conn->setFetchMode(ADODB_FETCH_ASSOC);
                }
                return $conn;
        }
}

?>

model.php

<?php

/**

getComments()  sorted by most recent first
listGuestNames()
addComment() - no blank comment, no SPAM

*/

require_once 'db.php';

class Guestbook {
    protected $db;
    function __construct() {
        $this->db = DB::conn();
    }
    function setDb($db) {
        $this->db = $db;
    }
    function getComments() {
        return $this->db->getArray(
            'select 
                * 
            from Guestbook 
            order by created desc');
    }
}

?>

guestbook.php

<?php

<html>
<head>
<title>Live Guestbook</title>
</head>
<body>
<h1>All my comments</h1>
< ?php

require_once 'model.php';

$guestbook = new Guestbook;
foreach($guestbook->getComments() as $comment) {
    echo '<h2>', $comment['name'], '</h2>', $comment['comment'], '';
}

?>
<h1>Add your comment</h1>
<form method="post">
<input type="text" name="name"/>
<textarea name="comment"></textarea>
</form>
</body>
</html>

?>

PHPLondon

Posted 10/7/2006 By Jason

I had a great time at the PHPLondon meeting. The meeting was held in the lounge above a English pub named “The Hope”. I was met at my hotel by Marcus Baker and Perrick Penet, and on the way we had a nice walk through London with a brief stop in another pub for a pint and a dinner of fish and chips. Here is a picture of me, Marcus and Perrick at the venue for PHPLondon.
Three SimpleTest Amigos, Jason, Marcus and Perrick

As soon as I volunteered that I might be able to attend the meeting, Marcus slotted me for a presentation. This worked out well, because after the PHP|Tek conference this past April, he had given me some pointers on a very good restructuring to my Test Driven Development talk. My original talk started with an intruction to testing, an overview of SimpleTest, an outline of test driven development, and culminated with a live demo where the audience selected the subject and we used TDD to arrive at a solution. I had structured the talk that way so that all of my information had already been imparted should the live demo fail miserably. Marcus pointed out that for someone who had not already been doing these techniques, the benefits of using TDD seem to vague and abstract, by moving the live TDD demo up into an earlier portion of the presentation, even someone who has never written a unit test would at least have a passing familiarity now, and the benefits described would thus be more tangible. This is clear evidence of Marcus’ teaching background seeping through, and was very good advise. For this talk, I organized it as: a brief intro to testing and SimpleTest, and a brief outline of TDD, then jumping into the TDD live session. After a few iterations of red-green-refactor, we hopped back to the presentation and had some very good dialog.

For the live demo, I started with this bootstrap file:

<?php

< ?php
error_reporting(E_ALL);
require_once 'simpletest/unit_tester.php';
require_once 'simpletest/reporter.php';
require_once 'simpletest/mock_objects.php';

class PhpLondonTestDrivenDevelopmentTestCase extends UnitTestCase {}

$test = new  PhpLondonTestCase;

if (TextReporter::inCli()) {
  require_once 'simpletest/ui/colortext_reporter.php';
  exit ($test->run(new ColorTextReporter()) ? 0 : 1);
}
$test->run(new HtmlReporter());

?>

The audiance selected an object whose job was to calculated information regarding an annual salary. Over several iterations we built up this test case.

<?php

class PhpLondonTestCase extends UnitTestCase {
    function testSalaryCalcExists() {
        $this->assertTrue(class_exists('SalaryCalc'));
    }
    function testGetDaily() {    
        $sal = new SalaryCalc(41400);
        $this->assertTrue(method_exists($sal,'getDaily'));
        $this->assertEqual(180, $sal->getDaily());
        $sal2 = new SalaryCalc(82800);
        $this->assertEqual(360, $sal2->getDaily());
    }
    function testNegativeSalaryThrowsException() {
        $this->expectException();
        $sal = new SalaryCalc(-41400);

    }
}

?>

which resulted in this code

<?php

class SalaryCalc {
    protected $sal;
    function __construct($sal) {
        if ($sal < = 0) {
            throw new Exception('Nobody works for free');
        }
        $this->sal = $sal;
    }
    function getDaily() {
        return $this->sal/46/5;
    }
}

?>

The entire power point presentation can be downloaded here.

Perrick followed up with a talk on using Agile development methodologies with PHP, less TDD which had already been covered ;). His talk generated a lot of lively discussion as well.

The facilities worked out well, the room was packed, and we had a very nice projector and screen. I was able to use the laser pointer/usb remote slide clicker given to me as a present for being a speaker at PHP|Tek this year.

After the presentations were over, we all enjoyed a few pints, many thanks to those attendees who choose to buy me a pint afterwards, I am very greatful. A few attendees were able to find out some personal details about me (and I think I broke a few sterotypes about typical American beer drinkers, though I by no means consider myself typical in these respects 😉 ). One attendee managed to talk me out of the only copy of my book I had with me, so he now has a signed copy :).

One thing an American should be prepared for in London is a lot of walking! Bring a decent pair of walking shoes, because if they are not good, you might have what happend to me affect you. The first thing is I have sore feet, and some good sized proto-blisters brewing. The second is I walk the soles off of my shoes…literally. I saw they were starting to split at the hotel, but I figured they would last the trip home where I could throw away my shoes. By half way through my flight back to Chicago from London, it became apearant the sole would fall off if I did not do something. I asked the stewardess if they had any tape, and somehow they managed to come up with a role of masking tape. I attempted the hidden repair by making loops of sticky tape and putting them between the sole and the bottome of the shoe, but it was obvious this was not going to work. I then bit the bullet and wrapped the tape around the outside of the shoes to hold the sole on until I could get to my bag and change into an alternate pair I had brought with me. If you don’t believe it, here is the proof, shot on the airplane shortly after the repair.
London kills Jason's Shoe

Speaking of the flight, I had a very nice gentleman next to me from Dice, a company specializing in matching qualified technical candidates with technical jobs. It was very interesting to contrast our different companies, a giant industrial manufacturer vs. an internet company, yet we had quite a number of similarities: use of PHP and the LAMP stack, use of Oracle databases, use of Siebel for a Customer Relationship Management system, and both of our companies use other open source solutions where they are beneficial. If anyone is on the job hunt for technical jobs, it is probably worth using Dice as a good starting point.

Places I Would Rather Be

Posted 9/12/2006 By Jason

Right now I am sitting in the B concourse of Chicago O’Hare airport. The next two flights to Pittsburg have been canceled, so I am going to be late to my corporate eBusiness summit meeting.

If I was not headed here, I would have to be at work responding to an internal audit for SOX compliance, so I guess things are not all bad 😉

Where I would rather be is with Marco and crew in Toronto at the PHP|Works conference. I am sad to miss the chance to hobnob with my PHP buddies :(

Another interesting conference coming up is the DC PHP conference in Oct. It looks like many of the familiar PHP faces will be around there as well.

If you are in the UK, perhaps we can hook up at the October PHP London meeting, I am on a business trip to the UK and was able to schedule it to attend this as well.

As I have mentioned before, there are many benefits to attending PHP conferences and meetings. Get involved, learn something new, and maybe I will see you there!

PHP Conferences

Posted 1/21/2006 By Jason

If you have never been to a PHP Conference, you owe it to yourself to make 2006 a year to attend one. There are of course the obvious benefits of attending the presentations and being able to see these presentations first hand as well as being able to interact with the presenters, ask questions, etc. A more subtle benefit is the networking which happens at these conferences. People whom you recognize from email addresses on mailing lists, pseudonyms on forums or names on the covers of PHP books are actually living breathing people (and usually fine, upstanding people at that). PHP conferences are a great opportunity to interact with both the presenters, conference organizers and the other attendees, who likely share many common interests with you, chiefly a passion for PHP and web development.

One conferences coming up soon I would like to attend is PHP UK 2006. Unfortunately time and distance make it impossible for me to attend. I consider Harry Fuecks a personal friend, though we have only corresponded via email and coordinated on projects. I would love to have the opportunity to finally meet in person (and perhaps purchase a few malted beverages 😉 ) Another PHPer I consider to be a friend is Marcus Baker, of SimpleTest fame, and a PHP London regular, is going to be attending and is helping to organize the conference. Many of the talks look interesting as well. Derick Rethans always gives informative talks, and I have read and was very impressed by Matt Zandstra’s PHP Objects, Patterns and Practice book.

There is a conference I know I am attending: php|tek 2006. I will be attending because I will be presenting talks on Design Patterns in PHP and Test Driven Development. I am looking forward to meeting everyone there, and hopefully I will see you there.

Advise for an Aspiring PHP Developer

Posted 11/2/2005 By Jason

A self described “aspiring PHP developer” recently asked me for advise on how to improve his skills since there were no PHP offerings at his school. Here was the advise I gave him.

Welcome to the world of PHP.

I have learned the most by following and participating in the discussion at the
SitePoint advanced PHP forum
(http://www.sitepoint.com/).

There are two coding techniques you can study that will pay great dividends:
Unit Testing (and in particular Test Driven Development, see
http://simpletest.org/ and http://www.testdriven.com/) and the use
of Design Patterns (see
http://en.wikipedia.org/
http://home.earthlink.net/~huston2/dp/patterns.html
and http://www.phppatterns.com/).

A project to investigate which combines much of this is WACT
(http://phpwact.org/).

Some good blogs:
http://www.procata.com/blog/feed/rss2/
http://www.lastcraft.com/blog/wp-rss2.php
http://netevil.org/feeds/rss.xml
and many others you can find through
http://www.planet-php.net/.

I would be remiss in not letting you know I have written a book on these
subjects as well :)
php|a

Hopefully that gives you something to chew on!

Looking this over, I realize I left out a critical resourse of the PHP Manual and the associated user comments, a great resource for PHP developers.

What advise would you give to an aspiring programmer?

phppatterns revived

Posted 10/27/2005 By Jason

If you are an aficionado of Design Patterns, and of PHP, then you may have noticed the hosting problems, and times outright disappearance, of the phppatterns website. With some hosting assistance from Jeff, phppatterns is back online. It is nice to see this valuable PHP and Design Pattern resource back online. One significant visible change is the use of Docuwiki as a back end (no comment on the chosen color theme from me ;), hey I am a programmer, not a designer, also).

Harry has also posted a detailed review of my Guide to PHP Patterns book. This is the most thorough review of the book I have seen to date, and I am happy to report that almost all of the feedback I have seen on the book so far has been positive.

Load Gun, Point at Foot, Shoot.

Posted 10/13/2005 By Jason

Sometimes it is hard to believe what some people do. I read on Derick Rethans site this post about a Fan Mail. This kind of a response saddens me as I think people are starting to forget their manners.

One thing people seem to constantly forget is that open source projects like PHP are fundamentally volunteer efforts. One can argue that Derick works for EZ Systems, and they derive revenue from PHP and pay him to work on PHP, but the fact is I know Derick spends significant amounts of “off the clock” personal time working on PHP — deep internal core parts of PHP that you and I use every day. Derick has freely chosen to work on PHP, and freely donates his time and effort to the endeavor.

People are rational beings. Everything we do is “good” in some manner, because that is how we are wired to motivate ourselves to do anything. We may disagree on the realized benefits or the percentage of the “good” we will receive from any given actions, but we should always try to remember that another person is trying to do the right thing from their perspective.

To the issue at hand, backwards compatibility breaks suck. This issue was not communicated very well, but if you were diligent, you could find areas where this was talked about on the internals list (for example here).

I think some of the core developers got a bit tired of responding to this particular issue, and started to push the “send a patch or forever hold your peace” line. I don’t think this particular line of thinking does the community a service either. I like to think I have contributed to the PHP community as a whole through discussion of use of PHP, example of code, contribution to projects written in PHP and by writing books and articles on PHP. All this aside, I have never contributed a line of C to the core of PHP, and I think there are many others in similar positions. Similarly, I think many people work hard to put together detailed bug reports, and these people are also contributing to the PHP community as a whole, though not in the same manner as the core developers.

Overall on this issue, I want to express my thanks to Derick for the many long hours he has put into making PHP a better language, and a great productive tool. Thank you Derick.

A Summers Work

Posted 8/18/2005 By Jason

I had a chance to summarize many of the projects I worked on this summer in a single photograph.

Books on chair

The biggest thing is the hardcopy versions of my book finally arrived! After nearly a year of nightly toil, it is quite a relief and satisfaction to hold them in your hand.

The books are resting on a ZCE tee shirt I won in a contest filling out a survey regarding the certification process. I’ll give you three guesses what shirt I will bring to the next PHP conference I attend (and the first two guesses don’t count). I passed the ZCE test at the php|tropics conference, so the shirt feels like a reminder of the efforts which culminated in my presentations there.

Lastly, this picture was taking in our three seasons room. After six years of staring at 2×4 framing, I finally decided to finish off this room. Earlier this summer I pulled runs of Coax and Cat5 to receptacles at the outer corners of the room (and wired in an outdoor GFI outlet on our deck), then insulated and dry walled the room. As you can see from the picture, I still have yet to finish the first round of taping and mudding.

Iterator Article in July php|architect

Posted 7/21/2005 By Jason

This months php|architect magazine has one of the chapters of my design patterns book as the lead article. You can download just the article as the sample chapter for the book.

I think the iterator chapter does a good job of being a representative sample of the book. I had both php4 and php5 code example, show a “pure” Gang of Four style iterator, as well as a more abreviated API version, and showed a bit of how to use the SPL iterator interface. It has a splash of UML, tons of code and SimpleTest based unit tests as well.

If you have any questions or feedback, feel free to leave a comment here, or post a message to the php|architect forum.

MVC Song

Posted 7/10/2005 By Jason

The MVC Song and the credit for me stumbling across it :)

Hilarious. Educational. A must listen.

The Wait is Finally Over

Posted 6/27/2005 By Jason

It is official, I am now a Zend Ceritified Engineer. To quote my notification:

Dear Jason Sweat,

Congratulations on passing the Zend PHP Certification exam!

As a Zend Certified Engineer you are now among an elite group that leads the
growth of PHP.

Now I should figure out how to work this logo into my WordPress theme 😉
ZCE Logo

I took the exam one morning during the php|tropics conference. There was a recent thread on SitePoint where I mentioned what I thought about the exam itself (my post is #46). Many thanks to Marco for footing the bill for the exam.

Looks like Paul read his email before me and got “first post” in the blogosphere from the newly minted php|tropics ZCEs.

Offical Patterns Book Announement

Posted 6/21/2005 By Jason

The book is getting closer. Yesterday we had an official announcement on the php|architect website, which pointed to the order page. It looks like Marco is giving a 10% preorder discount, so everyone should order 10 copies today, and effectively get a free copy. 😉

I would have also emphasized unit testing in the blurb. While there are a few PHP books out there which have chapters or sections on unit testing, I don’t believe there is any other book which emphasizes the practice as much as I have. Unit tests are not only present in the code download for each chapter, but are integral to the explanations in each chapter as well. Many times when I present examples of working code, it is within the context of a unit test. I also tried to explain the basics of Test Driven Development, and have a few examples shown using TDD iterations.

The Adapter chapter is off to layout so we are down to the last few chapters! I am really looking forward to holding the dead tree edition :)

The Specification Pattern

Posted 6/15/2005 By Jason

Last night I sent my chapter on the Specification pattern in for layout. This passes the > 50% mark for chapters through editing and off to layout as well.

This chapter was fun to write because it strays a bit from the Gang-of-Four/Fowler PoEAA design pattern mainstream. Fowler has written some articles on this pattern and Eric Evans covers it in some detail in “Domain Driven Design”. I first show a “hard-coded” example, and then a parameterized specification which can take a WACT DataSource object as the item being tested. The last example in the chapter shows how to create a composite structure of concrete specification objects to act as a “Policy”.

The chapter is an evolution of some early work I did with the Specification pattern in this thread.

By popular request, here is the complete table of contents:

  1. Preface
  2. Programming Practices
  3. The ValueObject Pattern
  4. The Factory Pattern
  5. The Singleton Pattern
  6. The Registry Pattern
  7. The MockObject Pattern
  8. The Strategy Pattern
  9. The Iterator Pattern
  10. The Observer Pattern
  11. The Specification Pattern
  12. The Proxy Pattern
  13. The Decorator Pattern
  14. The Adapter Pattern
  15. The ActiveRecord Pattern
  16. The TableDataGateway Pattern
  17. The DataMapper Pattern
  18. The Model-View-Controller Pattern
  19. Conclusion

Appendices:

  1. Patterns Quick Reference
  2. SimpleTest Testing Practices

update: Had some funny characters in my summary, removed them to see if it helps peoples feeds.

Happy 0xA B-day PHP!

Posted 6/8/2005 By Jason

Chiming in with the chorus, many thanks go out to Rasmus, and every other contributor to PHP, for creating a phenomenon.

Following the tradition of the other PHP anniversary posts:

What was I doing 10 years ago?
I was working for a small engineering firm in Iowa doing process control work in the steel industry. Our control system used artificial neural networks to optimize the control of electric arc furnaces. This work expanded into SCADA (supervisory control and data acquisition) and led eventually to me displaying this process control data on web pages via ASP and IIS.

When did I get involved with PHP?
In 2000, I was looking for a free—as in beer—way to create dynamic web pages for a partnership whose accounting I maintain. My UNIX administrator at work turned me on to the LAMP stack and I have never looked back. I have brought PHP into use for both web page development and batch scripting at work, and have written several articles, books and numerous presentations on PHP.

Happy birthday PHP, and many happy returns. Thank you PHP team for endless hours of toil.