php|architect’s Guide to Enterprise PHP Development

There’s a new book available for pre-order on the php|architect website, titled php|architect’s Guide to Enterprise PHP Development, by Ivo Jansch of Ibuildings.

This book is great for anyone who’s interested in learning how to use PHP in an enterprise environment. It has every step on the way covered, such as planning, development tools, deployment and much more. If you’re (planning on) using PHP in your company, this book is going to prove invaluable for everyone involved in the development process, going from developers to development managers or project managers. I believe pretty much everyone involved with software development can benefit from a book like this.

Also, as far as I know, it’s the first book ever on enterprise PHP development specializing on this subject. There still aren’t that much resources available around on enterprise PHP development, so I expect this book to be very popular on the PHP developer’s bookshelf. I definitively pre-ordered mine already! ;-)

PHPT (testfest) writing resources

The PHP TestFest month is almost over and we can already probably say it was quite a success. Of course it would be great if some of the test writers continue to occasionally write a new test or two, and for this occasion, I thought it would be handy to have a resource listing of presentations, websites and pdf’s that cover PHPT testing. Although I believe this is a decent list of resources I’ve actually used myself, I’m probably missing some, so this will be a work in progress and updated once in a while. :-)

First, some of the official PHP resources on PHPT testing (pretty much all of qa.php.net is relevant here):
http://qa.php.net/write-test.php
http://qa.php.net/running-tests.php
http://qa.php.net/tested-methods.php
http://qa.php.net/testfest.php
http://qa.php.net/phpt_details.php
http://wiki.php.net/qa/testfest

GCC code coverage page for PHP, which shows test code coverage for the most popular CVS branches. Some graphs and other compiling, testing and analysing information is also available:
http://gcov.php.net

This is the place you’ll need to go to acually submit tests if you don’t have CVS commit karma yet (it’s good for overall testing statistics too):
http://testfest.php.net

Next is a blog post on what Josie Messa has learned while writing tests. Interesting article which shows a lot of real code examples and issues that she dealt with while writing PHPT tests:
http://jmessa.blogspot.com/2008/05/lessons-learned-in-phpt-writing.html

Slides by Sebastian Bergmann, useful to prepare yourself for writing tests. This presentation tells about what PHPT testing is all about, how to properly write tests, and how you should prepare for testfest:
http://sebastian-bergmann.de/archives/777-PHP-Test-Fest-Slides.html

This is an article I wrote, explaining a way to set up Mac OS X for writing PHPT tests. This doesn’t use the built in PHP distribution but instead prepares the OS for manually compiling and running PHP from CVS, with code coverage and all the goodies:
http://felix.phpbelgium.be/blog/2008/05/22/writing-phpt-tests-on-your-mac/

Presentation by Marcus Börger with pretty extensive overview on testing (and PHPT testing in specific). This is one of the most complete presentations on the subject I could find:
http://somabo.de/talks/200703_montreal_need_for_testing.pdf

The blog of Zoe Slattery, which has 2 posts (and much more to come, undoubtly!) about testing PHP and PHP TestFest:
http://zoomsplatter.blogspot.com/

This is the official website of the PHPT testing framework:
http://phpt.info/

Of course you’re best off grabbing a CVS checkout of the PHP_5_3 (or 6_dev) source tree:
http://www.php.net/anoncvs.php

In the CVS checkout of the PHP source code, there is a interesting README file called README.TESTING. It provides useful information on how to test, testing conventions, how to handle failed tests and more:
http://cvs.php.net/viewvc.cgi/php-src/README.TESTING?revision=HEAD&view=markup

If you have questions regarding writing PHPT tests, there are several ways to go. First off, you can ask away at the IRC channel #phptestfest on irc.freenode.net. For any kind of QA or testing related question, you can also mail php-qa@lists.php.net mailing list, and subscribe to the mailing list on http://www.php.net/mailing-lists.php.

PHPBelgium: first meeting report

PHPBelgium community logoYesterday we had our first PHPBelgium PHP community meeting, organized by Michelangelo van dam and me. It was planned on 27th of may 2008, located in GC De Zandloper, Wemmel, Belgium.

With about 13 people on the RSVP list, we were quite pleased to see that much interest in an event we actually only announced a week ago :-) But because of the short notice, and also due to a related event in the Netherlands, some people had to cancel, which we of course understand. In the end, about 6 people attended the meeting (us included), but it was a very happy group, and we had a lot of fun.

First we introduced ourselves with a presentation we made (which can be viewed below, or on SlideShare). Then a general discussion about PHP came along, where we talked about PHP in Belgium, possible topics for future events, extension writing in PHP, Unit testing, PHPT testing, Guitar Hero (no kidding!) and more.

Quite some pictures were made, which can be found on Flickr. If you have interest in attending our next event (we’re organizing one event every 2 months), please have a look at our website at http://www.phpbelgium.be and subscribe to the RSS feed, visit us on IRC on the irc.freenode.net server, channel #php_bnl or follow @phpbelgium on twitter.

Thanks for everyone who could attend, and to everybody: see you next time!

Standard core PHP 5.3 extensions

When writing PHPT tests for PHP, it’s good practice to have a conditional --SKIPIF-- block to see if the test can be skipped when some extension you’re testing isn’t available. With the PHP_5_3 CVS branch (the one you should be testing against), some new extensions can’t be disabled, so the --SKIPIF-- block isn’t needed anymore. This applies to the following extensions: PCRE, Reflection and SPL.

In fact, the following extensions can’t be disabled so you can safely test against them without the --SKIPIF-- block:

  • date
  • ereg
  • pcre
  • Reflection
  • SPL
  • standard

For completeness, a short example for a Reflection test:

--TEST--
ReflectionClass::isAbstract() method
// THESE 2 LINES ARE NOT NEEDED --SKIPIF--
// REMOVE THEM! <?php extension_loaded('reflection') or die('skip'); ?>
--FILE--
<?php
 
abstract class TestAbstractClass {}
$abstractClass = new ReflectionClass('TestAbstractClass');
var_dump($abstractClass->isAbstract());
 
?>
--EXPECT--
bool(true)

Configuring PHP: --with-extension or --enable-extension?

This is a small thing that got me wondering in the past but it wasn’t until recently, when I started picking up developing PHP extensions, that I wanted to know: when does one use --with-extension and when does one use --enable-extension? The answer is easy but you just have to remember ;-)

--with-extension is used if you want to refer to an external directory or libraries, for example --with-mysql[=DIR]. The extension can’t be built without external mysql headers, thus the –with switch.

--enable-extension is used if you just need to tell PHP to enable the extension in question, for example --enable-mbstring. Mbstring support is built in with PHP, you just tell it to enable it.

You should know that, if you are building your own extension, you should only pick and use the one that is most appropriate for your extension, but never both.

Writing PHPT tests on your mac

This is a short tutorial on how to set up a Mac with Mac OS X to prepare for writing PHPT tests. This preparation includes installing some extra software that enables you to checkout and compile the PHP_5_3 branch of the PHP source without problems. Furthermore we’ll install some tools that make it possible to get an easy overview of untested PHP code with code coverage reports.

This overview assumes you’re working on the latest version of Mac OS X, being 10.5 (Leopard). Some terminal experience also comes in handy!

1. Installation of XCode

Apple’s XCode is used to create a development environment on your mac. For example, the GCC compiler, automake and other build tools are installed with XCode. Notice: you do need XCode version 3 or higher. The files needed for the installation can be found on the Mac OS X installation DVD or on the Apple Developer Connection website (http://developer.apple.com)

2. Installation of MacPorts

MacPorts is a package manager that will ease the installation, configuration and updating of open-source software on your mac. We’ll use MacPorts to install some tools that are needed in our development environment. You can find the MacPorts installation files on http://www.macports.org. By default, the MacPorts binaries are installed in /opt/local/bin. To make working with the terminal easier, we’ll add the directory to our PATH variable. Let’s open Apple’s Terminal.app and type:

# echo 'export PATH=/opt/local/bin:$PATH' >> ~/.profile
# source ~/.profile

Trough MacPorts, we’ll install a lexer used by PHP (re2c) and a tool to download files (wget):

# sudo port install re2c
# sudo port install wget

3. Lcov installation

Next up, we’ll install lcov. Lcov is a graphical front-end for gcov, a code coverate testing tool for the GCC compiler. Lcov isn’t available in the MacPorts repository, so we’ll need to install this manually:

# sudo mkdir -p /usr/local/src; cd /usr/local/src
# sudo wget http://downloads.sourceforge.net/ltp/lcov-1.6.tar.gz
# sudo tar -xzvf lcov-1.6.tar.gz
# cd lcov-1.6

Due to a non-compatible ‘install’ binary on Mac OS X, the installation can’t be completed with the -D switch. This has no implications on the actual resulting installation, but it does need to be changed to suppress the error messages:

# sudo nano /usr/local/src/lcov-1.6/bin/install.sh

Go to line 34 (install -D $SOURCE $TARGET) and remove the -D switch. Afterwards you can install lcov with the following command:

# sudo make install

4. Installing the right flex version

Now we need to install a alternate flex version. By default, Mac OS X has the flex lexical parser installed, but the installed version is not compatible with PHP. Thus we’ll install an older flex on an alternate location, which then can be used for compiling PHP:

# cd /usr/local/src
# sudo wget http://dfn.dl.sourceforge.net/sourceforge/flex/flex-2.5.4a.tar.gz
# sudo tar -xzvf flex-2.5.4a.tar.gz
# cd flex-2.5.4
# ./configure && make
# sudo make install

5. Installing the right autoconf version

If you compile PHP, you’re advised to use autoconf version 2.13. Since Mac OS X comes with autoconf version 2.61 by default, we’ll install an older autoconf version, which again can be used when we’re compiling PHP:

# cd /usr/local/src
# sudo wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.13.tar.gz
# sudo tar -xzvf autoconf-2.13.tar.gz
# cd autoconf-2.13
# ./configure && make
# sudo make install

Let’s change our PATH variable. That way, the right lcov, flex and autoconf binaries will be found by PHP:

# echo 'export PATH=/usr/local/bin:/opt/local/bin:$PATH' >> ~/.profile
# source ~/.profile

6. Downloading the PHP source

We create a directory to put all our sources and other related files:

# mkdir ~/phptest; cd ~/phptest/

Now we can check out the PHP source code using anonymous SVN:

# svn checkout http://svn.php.net/repository/php/php-src/branches/PHP_5_3 php-src-5.3 
# cd ~/phptest/php-src-5.3
# ./buildconf

7. Compiling and testing of PHP

Everything is now set up to write PHPT tests or just explore and hack the PHP source code. If you want to configure and compile PHP, use the following commands:

# ./configure && make && make test

If you also want to enable code coverage results, use the following command:

# ./configure --enable-gcov && make && make lcov

Optional, you can also pass the TESTS variabele to the make lcov command to only run a specific test-case (of course, this speeds up compiling the PHP source):

# make lcov TESTS=ext/foo/tests/bar.phpt

Next up, have a look at the lcov_html/ directory, where you can find the HTML code coverage results. Open your browser to view the code coverage, and write some PHPT tests to increase the overall coverage!

8. Some links to get you started on testing

PHP-QA: http://qa.php.net
PHP TestFest: http://wiki.php.net/qa/testfest
PHPT: http://phpt.info/

Update (09/07/2010): I’ve updated the article to reflect the change from CVS to SVN as version control system of the PHP project.

PHP London 2008, an overview

I’m just back from PHP London 2008 Conference, where I had a lot of fun and could attend interesting talks. 

After I arrived at about 8:15 in the Inmarsat conference building, I realised I was way too early. Not a problem at all, that gave me the time to have a look around at the different conference rooms and where the catering is located. Always look for the quickest way to grab a cup of coffee :)

The presentation I was looking forward to the most was Ivo Jansch‘s talk about Enterprise PHP. It was a great talk with a very easy to understand analogy to bricks and buildings (maybe Ibuildings? :) ), which made this humorous talk one to enjoy. It does overview the key points of enterprise development very well, which definitely got me (even more) interested in his upcoming book about Enterprise PHP development. Imho, there’s totally not enough ‘awareness’ of using PHP in an enterprise environment, so everything that changes this is a good thing!

Next up were the guys from vBulletin (Scott MacVicar and Mike Sullivan), giving a talk about their experiences while being on the vBulletin team for a couple of years already. For some points, they elaborated on what Ivo just skimmed on at the talk before, but they also gave some interesting insights on what problems and issues you could encounter while developing such a big project.

Of course I’ve been waiting for the Frameworks panel discussion too, having experience with 2 out of 3 discussed frameworks (Zend Framework and Symfony that is), I was looking forward to what items they would bring that made ‘My framework better than yours’. I actually liked the total lack of flaming and instead having a nice overview of where the framework in question shines and what the strengths of it were.

The last talk on the planning was Derick Rethans, presenting a keynote about his experiences with PHP in all those years that PHP has grown from a little personal script to help Rasmus out, to a mature, object-oriented language that can be used in a multitude of environments. Too bad we weren’t able to attend the whole keynote as we had a a Eurostar train to catch. I did already see this presentation at the Internation PHP Conference 2007 , and it was nice to see that parts of the presentation were updated.

In general, this was a very good (but way to short) conference.I definitely had a lot of fun, met various interesting people and enjoyed the presentations and talks that were given.

Fosdem 2008, afterwards.

Been to fosdem 2008 yesterday, and generally speaking it was (again) very cool.

I got the chance to meet with various interesting people, got around to attending only one talk (Unicoding and PHP 6) but it was definitely interesting to see some of the PHP 6 (and to some extent, PHP 5.3) unicoding goodies in action.

The event still goes on today, so if you’re in the neighborhood, you can still take a visit.
More information (+ slides and video recordings of the main presentations), see fosdem.org

Dutch PHP Conference 2008

All the cool geeks are going, so you better also be present!
The conference website is released just today, and the dates are known.

Mark your calendars for the 13 and 14th of june, and be part of the one and only Dutch PHP Conference, with an already very impressive speaker line-up! Don’t wait for too long to register for the event, word on the street is that tickets are very quickly sold-out.

The venue will be in Amsterdam, more information on http://www.phpconference.nl.

Fosdem 2008

I'm going to FOSDEM, the Free and Open Source Software Developers' European Meeting