Category Archives: Planet Ibuildings

  • [Ivo Jansch]Good use of public, private and protected in OO class design July 20, 2010

    It’s been a while since my last post. My blog pattern these days is that I write a blog post when I have an opinion that doesn’t fit in a tweet. :)

    There’s been a debate in the PHP community about the use of public, private and protected. Apparently the Symfony project has decided that private is Evil, and should not be used. I don’t care much about Symfony as I’m not a user, but it turned to a discussion on OO theory when Stefan defended the position by claiming that you ‘should have the right to extend a class’s methods if it doesn’t support the use case you have’.

    On Twitter, things got worse. Marco Tabini mentioned private has no role in open source code insinuating that it’s about who can read the code and Travis Swicegood mentioned that protected code indicates code that is in the wrong place and later that it prevents unit testing because it creates un-testable units of code.

    Before I answer to those claims, let me give you an example of a class that uses public, private and protected in the way they were intended.

    The Account class

     
    class Account
    { public function depositFunds($amount) { $this->_updateBalance($this->currentBalance()+$amount); }
      protected function _updateBalance($newbalance) {
      if ($this->validate($newbalance)) {
      $this->__updateRecord($newbalance); $this->__publishAccountUpdatedEvent(); } }
      private function __updateRecord($newbalance) { $this->getModel()->store($newbalance); }
      ....
    }
     

    As the designer of this class, I have the following considerations:

    • Somebody that uses my class in an application will need to be able to withdraw and deposit funds. This is the only feature I offer to my class users; it is my class’s responsibility to take care of handling the withdrawal and deposits.
    • Derived Account classes (which will follow the ‘is a’ scenario of inheritance and thus will probably be special types of accounts, such as savings accounts) should be able to withdraw and deposit, but can also call _updateBalance to update the balance directly. This is something I trust derived classes with.
    • The actual act of updating the underlying model is my responsibility and my responsibility alone. This method is private because I do not want other classes to call this function directly. The only way to call __updateRecord is through the protected _updateBalance call. This way I ensure that there’s always validation and that notifications get send out. This makes my application more robust because the things that need to happen, will happen. I trust derived classes to update the balance, but the trust goes only so far; the actual act of updating the underlying model is my responsibility.

    This process is called ‘encapsulation’.

    Looking back at the arguments

    Now let’s look again at the arguments.

    • Stefan says that he needs to be able to override things if they don’t support his use case. The above class is designed to support a variety of use cases, through the interface it offers to users and inheritors. Generally a use case is defined by the public methods a class offers, and that should be sufficient. If not, the class may have been designed poorly. Inheritors can change the use case slightly, but only to the extent that they do not endanger the overall robustness of the application.
    • Marco says that private has no use in open source projects. The above example could be part of an open source project. The decision to make a method private had nothing to do with the fact that others could read the code, nor did it have anything to do with the fact that the code cannot be changed. If this is an open source package and you want to change it because in your world you do want unvalidated account updates, you can simply download the code, change the code and be happy.
    • Travis claims that ‘protected’ signifies code that is in the wrong place. On the contrary, in my example I’ve used protected and private deliberately to design class responsibility.
    • Travis also says that it is a problem for unit testing because it creates an untestable unit. I would argue that in this case, the ‘unit’ is the account and its public interface. A unit test should use only the public interface which is sufficient to verify whether or not the class is doing the right things, and whether it’s doing those things right. If the class contains so much code that you need unit tests that test the smaller internal functions of the class, you may be looking at a class that has too much responsibilities and that should be split up.

    The arguments seem to be mostly about what you can derive but the number 1 use case of access specifiers is defining what you can call. In my opinion, preventing people from using private to make deriving easier at the expense of no longer being able to specify who can call what and define class responsibilities, is wrong. In most cases where this is a problem, the actual problem is poor class design.

    There are of course numerous situations where the designer of a class has made the wrong decision and made a method private that should’ve been protected. In such scenario’s, changing it and contributing a patch seems the right thing to do. However removing the use of private from a project entirely because some can’t handle the difference, seems very wrong.

    Other languages

    PHP is not the first language to support private, public and protected. Other languages have seen similar debates, with more or less the same underlying principles. Ruby has built in ways to circumvent private/protected/public so functions can be unit tested. C++ is the most advanced when it comes to OO design. It supports ‘private inheritance’ and ‘protected inheritance’. See here for examples. Also it supports a ‘friend’ feature that allows a class to define ‘friends’ that can access their private members. If classes befriend their unit tests, then unit tests can access private functions.

    PHP doesn’t have a ‘friends’ feature (I nearly said ‘PHP doesn’t have friends’ which does sound funnier but is not what I meant ;-) ) nor does it have ways to circumvent the access specifiers for unit tests. That doesn’t make the concept of private and protected any less useful though.

  • [Lorna Mitchell]SugarCRM 6 Installation Error July 18, 2010

    I noticed that SugarCRM have just released their new version 6.0.0, and since my sugarcrm installation is madly out of date and I’m about to start using it again, I thought I’d just throw the old one away and install from scratch. I had no problems until I reached the final installation stage, when clicking the “install” button would return a 404. This is tedious because then you have to follow the instructions and change config.php so that “installer_locked” is false (but the installer does remember all the information you give it, which makes this less annoying)

    After a couple of times around the loop I looked properly at the warnings on that final page before the “install” button, and made some php.ini changes in line with what it requested – increasing the memory_limit and the upload_file_size. I also installed php5-curl (I’m an ubuntu user so this is just an aptitude package for me) and the install ran like a dream at that point. I’m disappointed that SugarCRM couldn’t give me better feedback than just a 404, but it seems like it needed some settings that I didn’t have – so if you see the same behaviour, don’t give up but heed the warnings and it should be able to install itself absolutely fine. Hope this helps!

  • [Lorna Mitchell]Giving Up The Day Job July 13, 2010

    The In-A-Nutshell Version I have resigned from Ibuildings. I will complete my notice period here in a couple of weeks and then move on to a wide and interesting variety of well-paying freelance assignments covering development, consultancy, writing and speaking. Hopefully.

    The slightly longer version really is this. Two and a half years ago, I left a job at a type of company I usually describe as a yet-another-website company, where literally every new project was another CMS website. Which was fun for about the first 4 months and got old pretty quickly. Two and a half years at Ibuildings and I haven’t done yet-another-anything, the projects have been technical, challenging and my colleagues are the best qualified set of people I’ll probably ever work with.

    Along the way I’ve also done a wide variety of other things, most of which are achievements beyond my wildest dreams, some within the scope of this job and some on my own time but of course influenced by all that I’ve learned. I’ve delivered training, led projects, been published, become a regular conference speaker and travelled internationally doing so, collaborated on an open source project, edited a developer portal and hosted a major international PHP conference. I’ve even learned to say those things about myself in public without feeling too much of a fraud!

    At this point, there are so many things I want to be doing, writing, speaking and so on, as well as some interesting development projects, that holding down my 9-5 as well has become untenable; that’s the main motivation for this change. I don’t intend to take another full time job, although I don’t have a lot of paying work lined up so please bear in mind that I am looking for some ;)

    Things I would like to be doing:

    • Working with development teams on skills, tools and process (think teach a man to fish, rather than sell him a fish)
    • API development
    • Technical writing
    • Meeting cool and interesting people and embarking on cool and interesting projects together

    Advice on achieving any or all of the above is appreciated – if any of you can also think of me when discussing business, write me a linked in recommendation, or retweet my announcement of my news, that would be fabulous!!

    If you’re still reading, then I’ll share a little something with you. I decided that with a career move, I needed a little rebrand, so here is my new angel avatar. I hope you like her :)

    Wish me luck in my new (ad)venture, I’ll be keeping everyone up to date as always!

  • [Lorna Mitchell]Retrieving Product Attributes from Magento’s V2 API July 12, 2010

    I’ve been working with the API for Magento in recent weeks and I had a bit of a struggle explaining to the V2 API which attributes of a product I wanted to retrieve. Actually I had issues talking to the V2 API at all, but that’s a different post so I’ll skate over those for now. Instead I thought I’d share (or rather, record for the next time I have the same problem!) how to specify which attributes about a product to retrieve.

    It actually wasn’t complicated but without V2 API documentation, it wasn’t at all clear what to feed in to get the result I was looking for. It turns out you can just pass an array of desired attributes, shown here with the info method from the product_catalog:

        // connect to soap server
        $client = new SoapClient(‘http://magentoinstall.local/api/v2_soap?wsdl=1′);

        // log in
        $session = $client->login(‘user’, ‘pass’);

        // product info
        $attributes = new stdclass();
        $attributes->attributes = array(‘product_title’, ‘description’, ‘short_description’, ‘price’);
        $list = $client->catalogProductInfo($session, <sku>, NULL, $attributes);
     

    There were two tricks – one was realising that I could pass that final (undocumented) argument, and the other was understanding how to format that. Hopefully anyone doing battle with the same thing will find this post and get over this little challenge much faster than I did :)

  • [Lorna Mitchell]Speaking at FrOSCon July 10, 2010

    In August I’ll be attending FrOSCon in Germany for the first time, and speaking there. It’s a mixed technology conference, with rooms set aside for separate scheduling for various projects and technologies. I’ll be speaking in the PHP room, delivering “Working With Web Services”, a talk which covers how to consume all sorts of types of web service from PHP. I’m excited about that and even more excited to hear that I’ll also be speaking in the main track, where I’ll deliver “Open Source Your Career” – stories and advice about how involvement in open source can positively influence the career path for each of us.

    I haven’t visited this part of Europe before so I’m also including a couple of days to see the area, and really looking forward to the trip. Since there are technologies other than PHP, and since I’m rarely in Germany, I know I’m going to meet a lot of new people … and I can’t wait :)

  • [Ian Barber]Monte Carlo Simulations July 3, 2010

    Monte Carlo CasinoMonte Carlo simulations are a handy tool for looking at situations that have some aspect of uncertainty, by modelling them with a pseudo-random element and conducting a large number of trials. There isn’t a hard and fast Monte Carlo algorithm, but the process generally goes: start with a situation you wish to model, write a program to describe it that includes a random input, run that program many times, and look at the results.

    In each case, you’re taking a pot shot at the result, and over many iterations you should get a broad picture of the probabilities of certain outcomes. If these match observations of the real situation, your model is a good one. Alternatively, if you can achieve certain results through randomness that others put down to some other factor, perhaps there is more chance in the real situation that others have expected.

    As an example, lets imagine visiting an SEO expo, filled with 10,000 SEO experts. Now, 20% of the experts are creative copywriters and link profile experts who will help to make your site more usable, more readable, faster, and help drive traffic from disparate sources as they improve your search profile. The others are clueless keyword stuffers and link spammers, who will turn your site into an real mess.

    However, a given rank on a results page is dependent on an awful lot of things – how the site was originally, what other sites are doing, changes to google’s algorithms, temporary network and server effects and so on. Because of that, sometimes the bad SEOs get their sites onto the front page, and sometimes the good ones don’t. Let estimate that the good SEOs get their site onto the first page under a given term two thirds of the time, while for the bad SEOs it’s only one third of the time. Now, whichever SEO you ask claims to be in the good category, of course, so you ask to see the results for the last 5 sites they optimised. If they are all on the first page, can you be confident you’ve got a good one?

    We can set up a monte carlo simulation for that by simply looping over the five sites, and seeing which ones succeed each time, by chance, and which fail. Starting with our total 10,000 SEO population, how many good vs bad SEOs do we expect.

    <?php
    $tGood = $tBad = 0;
    $iterations = 10000;

    for($iters = 0; $iters < $iterations; $iters++) {
            $goodCount = 2000;
            $badCount = 8000;

            for($i = 0; $i < 5; $i++) {
                    $max = $goodCount;
                    for($j = 0; $j < $max; $j++) {
                            if(lcg_value() < 0.33) {
                                    $goodCount–;
                            }
                    }
                    $max = $badCount;
                    for($j = 0; $j < $max; $j++) {
                            if(lcg_value() < 0.66) {
                                    $badCount–;
                            }
                    }
            }
            $tGood += $goodCount;
            $tBad += $badCount;
    }

    var_dump(“Good SEOs: “ . $tGood/$iterations);
    var_dump(“Bad SEOs: “ . $tBad/$iterations);
    ?>

    After our 10,000 iterations, we see the numbers come out with a majority of good SEOs, but some bad ones have made it through:

    string(19) “Good SEOs: 270.0382″
    string(16) “Bad SEOs: 36.343″

    This is an example where we can use brute force to solve what would otherwise be an integration problem. Admittedly, this is not a very difficult problem, but the logic can be continued and refined into situations that are require more complex maths. The wikipedia Monte Carlo simulator page has a good description of how the value of Pi can be estimated by a Monte Carlo method, for example.

    Projecting The Future

    For a more complicated example, we can think about planning a development project. We’d like to take a set of estimates, and run them through a Monte Carlo simulation to see what kind of overall times we can expect. Imagine that we’ve taken a look at past projects, and concluded a few things about the estimate. Our estimates always come in a ‘best case’, ‘worst case’ variety, so we have a range of numbers. Most tasks are delivered somewhere within that range, usually well under the worst case, but there are small few that seem to go way over it.

    We decide to model this by assuming that worst case is actually 3 times that estimated originally. However, rather than assuming we have equal chance of getting any value in that range (a flat distribution), we want to model our chance of getting the lower results as being higher than getting the higher ones. This kind of distribution is called a power law, and we can use a function that models that distribution for our random function.

    <?php
    function powerLaw($min, $max, $n) {
            $max += 1;
            $val = pow(
                            ( pow($max, $n+1) - pow($min, $n+1) )
                                    * lcg_value()
                                    + pow($min, $n+1),
                            (1.0/($n+1))
                    );
            return $max - 1 - $val + $min;
    }

    function getTotalTime($estimates) {
            $totalTime = 0;
            foreach($estimates as $estimate) {
                    $totalTime += powerLaw($estimate[‘best’], $estimate[‘worst’]*3, 5);
            }
            return $totalTime;
    }
    ?>

    With those functions in place, all we have to do is feed in our estimates, and for each one run them through the getTotalTime function. We can do a number of loops of this, and look at the results that we get.

    <?php
    // our estimates
    $estimates = array(
            “login form” => array(“best” => 2, “worst” => 10),
            “forgotten password” => array(“best” => 8, “worst” => 20),
            “profile page” => array(“best” => 16, “worst” => 20),  
            “avatar upload” => array(“best” => 8, “worst” => 14),  
    );

    // conduct 10,000 trials
    $results = array();
    for($i = 0; $i < 10000; $i++) {
            $res = getTotalTime($estimates);
            if(!isset($results[$res])) {
                    $results[$res] = 0;
            }
            $results[$res]++;
    }
    ksort($results);
    ?>

    This gives us an array of results, from which we can calculate some estimates. For example, although the worst case from the estimates is 64 hours, if we want to account for 80% of the runs we’d need to allocate around 68 hours – and assuming our model is correct then our project would still have a 20% chance of going over!

    We can visualise this by using the Google Charts API, which helps to show how, while the bulk of runs fit around the original hours, there is a tail to consider of unexpectedly long delivery times:

    <?php
    $url = “http://chart.apis.google.com/chart?chs=450×200&cht=bvs”;
    $url .=&chds=0,. max($results);
    $url .=&chd=t:. implode(,, $results);
    $url .=&chbh=3,1,1”;
    echo $url; // url for google
    ?>

    A plot of the estimates from google charts

    The length of time runs along the horizontal access, number of trials that resulted in that time in the vertical access. The long tail of growing times of the estimate show why to get a more certain timescale we have to go way over our original worst case, but still having the project likely to be delivered somewhere in the original range.

    The nice thing about these methods is that they are fairly easy to get a grip of. You can plug in a randomness function of your choosing based on almost anything, and try modelling situations that otherwise would be hard to understand intuitively. By plotting the result of calculating statistics you can quickly try out scenarios and get a feel for different sort of effects, as long as there’s an element in the thing you are modelling that is chaotic enough to be effective random.

    Image Credit: Monte Carlo Casino by mfotinakis

  • [Lorna Mitchell]PHPNW10: Call for Papers June 29, 2010

    It’s official, PHP North West 2010 is definitely happening … and for that we’ll need some people to pop along and give a talk! As in previous years, we’ll first of all deal with selecting the papers for our main conference day, 9th October. Talks can be 60 minutes or 30 minutes, can be on any subject if you can persuade us it’s relevant to PHP developers, and speakers anywhere on the spectrum from expert to newbie are welcome.

    So what are you waiting for? Go submit your talk at our call for papers page. If you need more assistance then you should check out these resources (and yes, some of them are mine but I feel strongly about this topic and want all you interesting and hesitant people to start speaking!)

    Are you submitting? What tips would you offer to those thinking of doing so? Already we’re at over 50 submissions, more than last year, so competition is tough but oh my goodness, I’m so excited :)

  • [Lorna Mitchell]Accessing the Magento V2 API June 24, 2010

    Recently I’ve been working with Magento at work, and in particular with integrating with their API. Now, before I say anything more, I must say that I am always pleased when I see that these products do include some kind of API. The Magento one is a bit interesting, although there is some half-decent API documentation for the original API.

    However they have then released a new version of the API, with very little documentation. So here are two calls – one to the v1 API and one to the v2 – which I hope will help illustrate the differences. The example I’ll give is the customer list functionality, including filtering the result set – because this was a total mystery when I started working with the v2 API!

        $options = array(
            “location” => ‘http://magentoinstall.local/index.php/api/index/index/’,
            “uri” => ‘http://magentoinstall.local/api/’
            );
        $client = new SoapClient(NULL, $options);

        $session = $client->login(‘user’, ‘pass’);
        $list = $client->call($session, ‘customer.list’, array(array(“customer_id” => “42″)));
     

    To make the same call with API version 2, we need to address the method in a different way, using the structure in the underlying code as the method name that we call, and CamelCasing those, like this:

       $client = new SoapClient(‘http:/magentoinstall.local/api/v2_soap?wsdl=1′);

       $session = $client->login(‘user’, ‘pass’);

        $filter = new StdClass();
        $filter->filter = array(array(“key” => “customer_id”, “value” => “42″));
        $list = $client->customerCustomerList($session, $filter);
     

    I haven’t used either of the APIs a lot but once I was able to call the same method via both available services, I wanted to share the approach here in the hope that this would help someone else trying to solve the same problem. It is certainly not obvious from the documentation how to interact with the v2 API and I had some real puzzles getting the filtering working. These snippets are from my working code so I hope they are helpful to someone!

  • [Lorna Mitchell]Your Open Source Stories June 23, 2010

    In this post, I am asking for your help and input, although it might seem like a post about nothing in particular to begin with. Please keep reading!

    Last month, I gave a talk at TEK-X entitled “Open Source Your Career”. Personally I think that a lot of the high fliers in this profession use their community activities as a boost to their professional development, and I know that this has been true for me too. So in my talk I told stories about situations I’d met in my professional life and how I’d either achieved or made new opportunities by building on skills and experience (and network) that I’ve come across in my community activities.

    For example I said to my CTO, Ivo Jansch that I was giving this talk and he asked what it was about. I said that, in a nutshell, I didn’t think Ibuildings would have trusted any of their developers to host the Dutch PHP Conference unless they’d seen that person hosting events elsewhere – as a volunteer co-host of PHPNW, I gained some experience doing this sort of thing. His response really brought home how true it is that getting out there can reap rewards in ways we don’t expect – or in my case don’t even recognise. He simply said “one reason you have the job you have now is the fact that you did an oracle podcast for zend once which I heard when I received your CV”. It hadn’t occurred to me that activities like that would have helped when I was changing jobs.

    What I Need From You

    I’m giving this talk again, at FrOSCon in Germany in August. It was a huge amount of fun to deliver last time but I’d really like to pull in more stories from other people to include in my talk. So … have you ever got involved with something outside of your day job, only to realise later that it was a good career move? And would you let me tell your story?

    Answers on a postcard, by email, or in the comments field below. Any and all input is very gratefully received :)

  • [Felix de Vliegher]Using git-svn: making the switch June 17, 2010

    A lot of people are already convinced that Git has a good chance of replacing Subversion as the version control system of your choice in the long run. Git is in most ways far superior to SVN (If you want to know why, have a look at this comparison). The feeling that Git is the way to go is only strengthened by the fact that major (PHP) projects are switching or planning to switch to the decentralized version control system: Zend Framework, phpBB, Symfony and Drupal, to name a few.

    Lots of projects are still stored in SVN repositories though. It’s not always easy to switch from one VCS to another, often projects have SVN-specific build scripts or infrastructure in place. If you’re interested in using Git but you’re still tied to Subversion as your main version control system, you can do so with the git-svn bridge.

    Note: this is not a git tutorial, I’m kind of assuming you’re already familiar with git and how to create, add, modify, delete, commit, diff and more. If you’re a bit unfamiliar with the git commands but know the svn toolset, have a look at this excellent svn to git crash course.

    Git svn magic

    git-svn – Bidirectional operation between a Subversion repository and git. The basic idea is that you keep your SVN respository in place (for as long as it will last), but still use git for all your day to day version control operations. When you feel like, you can then issue a command which will synchronise your git commits with the central Subversion repository. Let’s get started on the setup.

    I’m assuming you have a traditional SVN repository layout with trunk in project/trunk, branches in project/branches/* and tags in project/tags/*. The -s switch indicated you want git svn to assume this layout is in place, so it can transform the repository paths to remote git repositories. The parameter --no-minimize-url is sometimes needed when you don’t have read permissions on the full repository, since git will try to connect to the root of the repository because sometimes, this provides better tracking of history when you’re importing the project. This step will initialize a git repository in the current directory with the needed metadata information to fetch the svn repositories later on:

    $ git svn init -s http://svn.example.com/project

    Next up, we’ll fetch the history from the svn repository and store it inside our git repository. An optional revision parameter (-r) can be added to only fetch history from that revision and up:

    $ git svn fetch -r XXX

    You can also replace the previous 2 commands with the command below. The only difference is that the git svn clone command creates a new git repository directory for you instead of using the current directory, hence the last parameter which indicates the directory name:

    $ git svn clone -s http://svn.example.com/project project_dir

    Updating from and committing to svn

    When you do a git commit, these commits won’t be pushed directly to the svn repository. Interacting with the svn repository is done separately, so two additional commands are useful.
    Updating your repo with the latest changes from SVN (similar to svn update):

    $ git svn rebase

    Pushing your commits to the SVN repository (somewhat similar to svn commit):

    $ git svn dcommit

    Basically, right now you’re set to go and you can start working on your git repository like you would normally do. In my case, I wanted to know how to do some additional things. They might not be needed in your case, but I found them useful to set up my working environment.

    Working with branches

    Since you have imported the git repository using a standard layout (remember the -s from the git svn init), you have all branches and tags available as you normally would with an svn checkout. Have a look at those remote branches:

    $ git branch -r

    Of course, you can start working on these branches too. To create a local branch which tracks one of the remote branches, do:

    $ git checkout -b new_branch remote_branch
    # so, for example to create a branch 'release_1.5' which tracks remote 'release_1_5':
    $ git checkout -b release_1.5 release_1_5

    When you fetched the SVN repository into your git repository, it automatically set your local master repo to follow the remote trunk repository. If you want to change that (for example, to have a branch as default master repo), you can change it like this:

    $ git reset --hard remote_branch
    $ git reset --hard release_1_5 # example

    Fixing svn ignore

    Svn ignores aren’t automagically transfered to your newly created git project, but git does have a similar way of ignoring files or directories inside a project. Better yet, git svn provides a built-in command which looks for svn ignores. If you then add those to .git/info/exclude (locally) or .gitignore (project-wide), you have exactly the same setup as you would have with svn.

    $ git svn show-ignore > .git/info/exclude

    Fixing svn externals

    If you’re using svn externals, you might have to jump to some additional loops to set everything up. There’s no real replacement for svn externals, but one way Git manages to simulate this is by using submodules. Submodules are a bit cumbersome to set up, but luckily for us, there’s a script which searches your project for svn externals and checks them out as git submodules. Of course, it’s not guaranteed to work, but might make it easier to set it up. Get it here: http://github.com/andrep/git-svn-clone-externals

    I’m hoping this is enough to get you started on using Git, an awesome version control system with too much cool features to name. If I’m missing something, please let me know in the comments and I’ll be glad to update the post.

  • [Lorna Mitchell]DPC Retrospective June 17, 2010

    I spent most of last week and the weekend in (rather rainy) Amsterdam for the Dutch PHP Conference. This is an event that is in its 4th year, although I was attending for only the 3rd time. Two years ago, I spoke at DPC – my first conference talk. This year, I hosted the event, which was quite a different experience. The event is organised by my employers, Ibuildings, and I was astonished to be asked late last year if I would like to be its host. Hosting an event is quite a different set of anxieties from speaking at one, and although there were a few minor emergencies along the way (lost speakers, really “interesting” CfP submissions, a moment where only half the venue would have wifi and some sessions failing to run to time), nothing worth getting stressed over!

    The event was great (can I say that myself?) and with a world-class schedule, excellent speakers who all delivered on the day, sponsors who supported the venture and of course the attendees who showed up, took part, joined in with the uncon and generally made the whole thing into the fun it was – I could not have asked for more. As for the community friends who kept on sneaking up on me with a hug or a word of encouragement … I can’t ever thank any of you enough. On a very personal level it was fanstastic – I’ve enjoyed DPC for a few years and although the weather in Amsterdam was not so kind this year, the friends at the event (both the people I had already met and the friends I made while I was there) made it more than worth it.

  • [Lorenzo Alberton]The Art of Scalability – DPC10 wrapup June 13, 2010

    A wrapup of the Dutch PHP Conference 2010. Uploaded slides of my talk “The Art of Scalability – Managing growth”.

  • [Lorna Mitchell]Magic Methods on Think Vitamin June 7, 2010

    I’m happy to announce that my new post 9 Magic Methods for PHP is live on Think Vitamin this morning. I’ve written a series of posts about OOP for the site, with a few more to come, and these “underscore-underscore” methods make for some very neat tricks with PHP, which I’ve tried to show in the post. Hope you like it :)

  • [Lorna Mitchell]DPC10 Has an Uncon June 4, 2010

    As the Host of the Dutch PHP Conference this year, you can imagine I’m squeaky-excited about the whole event. This story goes right back to last year though, when someone (Ivo? Cal? I don’t know who) conceived the idea of including an unconference in this year’s event. DPC is easily one of my favourite conferences and although I work for Ibuildings, I wasn’t directly involved with its organisation last year. In the autumn I wrote a proposal for running the unconference, and it was agreed that we should do it. Fast forward a bit and I became the host of the main conference, which is great news but left a slightly abandoned unconference behind – until the PHPBenelux user group stepped up and will be hosting the unconference alongside our main event (thanks guys!)

    I’m so excited about the unconference, although I don’t know how our wider attendees will take to it as it hasn’t been done before locally. In order to include as many people as possible (and to keep the admin overhead to a minimum) we’ll schedule during the conference, on a first-come, first-served basis. This avoids the in-crowd getting voted into all the slots in advance; the uncon is for everyone to take part, not just for the people who are already well known! The uncon will also give us space to include extra on-demand sessions where people are wanting to see more about a particular topic, or see a demo of something a speaker mentions in a talk. Managing a changing schedule in real time will be interesting, we’re planning a two-pronged approach with twitter and Joind.in and I’m hoping this will allow attendees to hear about things they want to see in time to actually see them!

    Its a new venture and I’m really interested to see how it turns out … if you’re coming to the conference then I hope you will give the uncon a look (in between the other awesome sessions on the schedule of course) and also take the time to share your thoughts on this and on the event as a whole. If you’re going to be there – leave a comment and let me know :)

  • [Lorna Mitchell]Web Services Tutorial on TechPortal June 4, 2010

    I’m very pleased to say that today I have a a post about web services for PHP developers published on techPortal! OK so I edit techPortal so this is the written equivalent of introducing myself as a speaker but I enjoyed writing the post and I hope it’ll be a useful overview for PHP developers looking at web services and working with them.

  • [Ian Barber]Book Review: Expert PHP 5 Tools June 4, 2010

    Apologies for the quiet times on the site recently, but for a bit of slightly off-topic content, how about a book review! The book in question is Pakt’s Expert PHP 5 Tools by Dirk Merkel, which is a tour through a variety of processes and systems that the author suggests should be in use by any serious PHP developer. Each chapter covers a different tool, namely:

    1. Coding Standards
    2. phpDocumentor
    3. Eclipse
    4. Subversion
    5. Debugging
    6. Frameworks, primarily Zend Framework
    7. Testing, mainly unit testing with PHP Unit
    8. Deployment, using Phing
    9. UML
    10. Continuous Integration

    The book is aimed squarely at developers, though most of the advice only really applies if implemented by an entire team, so the natural audience is team leads or one man bands, where decisions regarding coding standards or framework usage are under their control. The topics are generally covered in a good degree of depth, and the author gives the impression of both having found the benefits of these tools for himself, and of having introduced them to other developers before. The writing and references are both presented in a way that should give them a fair lifespan, so the book should remain relevant for a few years, unless one of the particular system referenced falls completely out of fashion.

    Each of the books chapters reads much like an in depth tutorial on the subject – the kind of thing you’d find on IBMs developer works or similar multi-page article site. This is not necessarily a bad thing, but makes the book better as a reference for specific tools than it does as an cover-to-cover read. Some of the chapters go into more depth than most web tutorials I’ve seen – for example the phpDocumentor chapter is excellent, and really drills into the available annotations. However, some, such as the frameworks chapter, seem much more shallow, and the reader would probably be best served by reading the introduction then googling for more information. This does beg the question of whether you’d be pulling this book off your shelf that often – while not a document-the-api book it’s no slim volume, clocking it an over 400 pages, and once you have the general concepts in mind, there’s not necessarily that much to go and look for that can’t be easily found online.

    Overall, I liked the book, and learned (or possibly re-learned) a few things about phpDocumentor and UML. The book is clearly typeset and easy to read, though the occasional proof reading error does crop up – misspellings that pass the automatic spell check like ‘design patters’. For someone that has been developing for a few years in a fairly static environment it’s a good way to gain exposure to the core tools that make up a modern development process. That said, I would have preferred the author to be more descriptive in the challenges and benefits he has faced using and implementing the tools in real projects, and left some of the detail of their use to the (often excellent) online documentation. For example, I don’t see any value in the Zend Framework introduction over the quick start guide on their own website, but there is a world of difference between your first ZF app and releasing a site based on it.

    Alternatives wise, there aren’t that many general, advanced PHP books. On the content, Ivo Jansch’s Enterprise PHP Development covers more of the software development life cycle, but doesn’t got into the same level of depth in individual topics as this book. When grabbing the links I noticed Wrox have a book called Expert PHP and MySQL Programming, which I haven’t read, but from the contents seems to cover some more advanced topics, and less of the general development infrastructure than Expert PHP 5 Tools.

  • [Lorna Mitchell]The Unavoidable PHPWomen June 4, 2010

    I’m subscribed to a number of women-in-tech mailing lists because, well, I’m a woman in tech. Every few months or so a thread will come round about a technical conference with no female speakers. The issues around this are many, lengthy, and not something I want to write about here (or not today anyway!).

    I was pleasantly surprised to note, then, that at the recent TEK-X conference, there was one slot where you could not AVOID seeing a female speaker. While Elizabeth Marie Smith delivered her slightly ranty “Cross Platform PHP”, Ligaya Turmelle was sharing her wisdom in her session “Replication with MySQL”, and in the remaining track there was a community roundtable, with my noble self on the panel! (OK so a panel is not a talk but hey, bear with me!)

    I want to say thanks to TEK-X for being an amazing conference, to the community for being generally fabulous, and to the women in particular for being awesome beyond belief – this was a good day :)

  • [Mark van der Velden]Connecting from PHP on a non Microsoft OS to MSSQL with a domain account June 4, 2010
    I was asked to create a web interface front-end with Microsoft Dynamics CRM as back-end. But I had some troubles setting up the connection, since it has to be done using a domain logon. This doesn’t have to be a problem at all, unless your configuration is wrong! In this article I’ll explain a few things and point you in the right direction when you have login problems.
    As stated earlier, the server running the PHP installation is not Microsoft. In this case a AS400 installation, but it could’ve been a Linux installation also. I’m using PDO for this article and PHP version 5.2.11. Even if you don’t want to use PDO, I recommend using it only for debugging (if possible) since that will give you *most likely* more debug information then the mssql_* family.
    When using PDO with a MS-SQL database, you’ll need to supply “dblib” as driver and DBLib uses FreeTDS as underlaying library. FreeTDS can be a source of troubles when you’re trying to connect, if not configured properly. So I’ll kick-off with a little information about it. Don’t skip it if you have login problems!

    Continue reading “Connecting from PHP on a non Microsoft OS to MSSQL with a domain account”

  • [Felix de Vliegher]phpDay Italia 2010 June 1, 2010

    First things first: looking at the post date, it’s been more than a year since my last post. No excuses here, it’s just how it is. I’ll try to post a bit more often, but can’t promise anything :)

    A while ago, I was invited to phpDay 2010 to speak about a subject I like a lot: Gearman. A PHP conference in Italy sounds pretty cool to me, my employer was sponsoring the conference and I’m always glad to give a presentation about topics I’m passionate about. Not surprisingly, I looked forward to phpDay 2010 quite a lot.

    Even though the Milan airport was still closed 3 days before the conference started (thanks Eyjafjallajökull), I still managed to take a flight from Brussels through Milan to Pescara airport. The conference venue still was a 50 minute drive away from the airport, but luckily Cesare and Fullo were incredibly kind to pick me up at 23pm and even took me to a very late dinner at a local restaurant. After a nice dinner, I checked into the hotel which was 50 meters from the Alba Adriatica beach, how sweet is that!

    The conference venue itself was located a bit further inland, but only a 5 minute drive from the hotel. The venue actually was a former university building which wasn’t used anymore. It made a good conference venue, with room for different tracks and a main hall/lobby. I was quite glad to see that there was a separate english-spoken track aside from the Italian talks who still were in the majority, but the conference organizers told me they are in the process of migrating to a more internationally-focussed (and thus english-spoken) conference, which of course is a good thing.

    I did manage to catch a few sessions besides working and attending the ‘hallway’ track. I specifically looked forward to Kore’s talk on Arbit, which is the project tracker you’ve wanted all along. Very interesting to see the motivations, architectural descisions and future roadmap of the project. I also went to see Dustin’s talk on YQL, which I’ve heard of before but never really used. It was a clear talk which described the possibilities of YQL, and even though I still have my doubts, I can definitely see where it could be useful too. One of the last sessions of the day was mine, and it really surprised me how much people were interested in Gearman and attended my talk. Overall the talk went good I think, I hope all attendees got something out of it.

    After the first day, all speakers were taken to an Italian fish restaurant, with an amazing amount of food served for each person, so I was really stuffed, but the food was really good so I didn’t mind a thing. On the evening of the second conference day, all speakers were again taken to a restaurant, probably even nicer than the night before. Amazing food, good company, what more can you want :)

    On saturday, I had to leave early because of previously planned appointments and again, the commitment of the phpDay organisation shone again. Cesare drove me to the airport at 6:30 am (thanks again for that!) so I could catch my flight back to Belgium. Even though it’s the first time I attended phpDay, it completely surprised me (in the good way!) in terms of organization and taking care of their speakers. There’s definitely growth in the Italian PHP market and it’s good to see some Italian PHP conferences too. Definitely one to put on the PHP conference calendar next year!

  • [Lorna Mitchell]TEK-X: Conference Report May 28, 2010

    Its been quiet around here recently, partly because I have been really busy and partly because I was in Chicago last week for the wonderful TEK-X conference. It would be very cool to get to go skipping around the world to conferences, however people paying for my airfares do seem to like me to perform some useful function while I am there and this was no exception with one tutorial and two talks to deliver, plus an appearance on a panel. I’ve attended this conference in previous years however so I knew it would be well worth it :) My sessions and an overview are outlined below:

    PHP Best Practices

    I was privileged to get a tutorial slot alongside my good friend Matthew Weier O’Phinney for a second consecutive year. This year we presented “PHP Best Practices” which was a lot of fun. We squabbled over topics and took turns presenting them from our own point of view. A description of the session and a link to the slides are on the joind.in page if you are interested.

    Subversion in a Distributed World

    Now that this talk is finally over, I don’t mind admitting that this was the one that I regretted submitting pretty much from the day it was accepted until the day I delivered it, including some rather sleepless nights. It was an adaptation of my “git folks are fanbois” bar rant but I got so concerned that I wasn’t supporting my accusations with facts that it evolved into a very coherent evaluation of what I consider to be the four main version control tools around at the moment: Subversion, Mercurial, Bazaar and Git. The talk went over better than I could ever have dreamed, and again you can find description, feedback and slides on the relevant joind.in page. If someone could please stop me next time I submit a talk that needs as much work as this, that would be awesome!

    Open Source Your Career

    I almost didn’t submit this talk, since its so very difficult to get a community talk accepted at the big conferences. They usually have one, at most, and I wasn’t sure I was in the top one of submitters on this topic. But, I had a transatlantic airfare to justify and I figured it might make a good second talk – I also know Cal well enough to know he likes a slightly contraversial take on these things. When he accepted it I was fairly surprised and actually quite nervous about spending an hour talking about myself in a conference session! I spoke without slides, so there aren’t any, but you can read the outline and feedback on joind.in. In a nutshell: get out and do things, you will reap the benefits one day.

    In Conclusion

    I had a great time in Chicago, and also managed some touristy outings into Chicago:

    Garden in the City The Bean

    The conference itself was quite a rollercoaster, not least because every session I delivered was written from scratch for this conference and I spoke at two other big events this year already – 4 sessions over 4 days is a tall order however you look at it and I had pushed my own boundaries a bit with the talks I submitted (for the record, I submitted plenty of perfectly nice, ordinary, technical talks that somehow didn’t make the cut!) On the final morning I delivered the career talk and then immediately sat on the community panel. I was aware of people saying to me “have you seen twitter?” but I had to turn around between sessions so I just nodded, smiled, and got settled for the next session. The upshot of that was that I sat in Marco’s closing remarks and read 2 hours worth of tweets about me, plus all the joind.in feedback on both sessions, all in one go.

    At the risk of understatement, the feedback was totally out of this world, I couldn’t believe how well the sessions had gone over and it took me about 3 days to get over the shock … which is another reason it took me so long to write this post.

    I’d like to say thanks to everyone who was there, left feedback, helped me prepare or just showed up to the conference and joined in the event as a whole. Stay in touch and I’ll see you all next year :)

  • [Lorna Mitchell]Podcast: How and Why to Become a Speaker May 11, 2010

    This is a podcast version of my rant-in-the-bar advice to anyone thinking about speaking, or wondering how to begin. Personally I think many more people could be sharing their expertise at events than actually do so, and I would really like anyone who wants to get involved to have a starting point. So if that’s you, and you have a spare ten minutes to listen to my thoughts on the subject, then the mp3 is here.

    Let me know what you think, and if you have any other advice you’d give to someone who isn’t yet speaking.

  • [Mark van der Velden]PHPUnit conditional test based on a PHP version May 10, 2010

    I had a problem with running test cases on multiple CI environments, where one of the two runs on PHP 5.2 and the other on PHP 5.3. This basically meant that all our pretty PHP 5.3 code caused the builds to fail on the 5.2 only machine. To solve this problem I needed a way to skip tests when the PHP version was less then 5.3.0. Besides the reason I needed this for a -less then ideal- setup. This can also be a generic way to skip certain tests, based on a PHP version.

    class someTest extends PHPUnit_Framework_TestCase
    {
        public function setUp()
        {
            // Testing if we are dealing with version 5.3.0 or higher
            if (!version_compare(PHP_VERSION, ’5.3.0′, ‘>=’)) {
                $this->markTestSkipped(‘Invalid PHP version, unable to run tests.’);
            }
        }

        public function test_testFoo()
        {
          // .. some awesum test case .. \\
        }
    }
     

    You can also use the cool @depends annotation of PHPUnit and put the version logic in a test. This has my preference, but it’s not always possible. In case you have some code that simply can’t be parsed by the older PHP engines.

    If you know a better way to do this, please share!

  • [Lorna Mitchell]Speaking at PHPNW May May 10, 2010

    Next week I’m speaking at the PHPNW User Group in Manchester on Tuesday Evening, 4th May – full details of the event are on upcoming.org. The talk isn’t directly about PHP though; I’ll be giving my “Open Source Your Career” talk, discussing how contributing to the community can really help your professional rise. I’ll be giving the this talk at the TEK-X conference in Chicago a few weeks later as well, hope to see you at either one event or the other!

  • [Lorna Mitchell]Accessing the Magento Web API May 10, 2010

    I’ve been working with the Magento Web API lately, and the first problem I ran into was actually getting access to it. Contrary to its reputation, I found some perfectly good documentation outlining how to connect to the service and use it. I thought I was on to a winner but I kept seeing:

    Fatal error: Uncaught SoapFault exception: [2] Access denied.

    Further investigation led me to this forum post – web services are separate users and you must first set them up through the admin screens – and make sure also to allocate roles to them.

    The slight pitfall at this point is that you create a username and an API key – these then become the apiUser and apiKey variables mentioned in the documentation. The key is basically a password, its starred out in the settings and you have to enter it twice. Now I know that, I can log in to my service! Hope this helps someone else get to the point faster than I did.

  • [Lorna Mitchell]Importing Data to Joind.In May 10, 2010

    As a conference organiser I work extensively with the site joind.in, which allows attendees to comment on sessions at a conference. Recently the site has also started supporting sessions with both times and tracks, making it indispensable as a way of keeping track of all the sessions during an event. The only downside is entering all the data into it!! Joind.in does have some import functionality, which I recently rebuilt to reflect the timings and track changes, however this only accepts XML at present, so there is still some preparation work to get your data ready to import.

    I know I’m not the only conference organiser who will have this problem so here’s my step-by-step guide to getting talk information into joind.in, easily and quickly. For up-to-date documentation on the joind.in import process and the official data format description, see http://joind.in/about/import.

    Set up Event and Tracks

    Step one is to submit your event to joind.in. When it is approved by the administrators you will receive notification and it will appear publicly on the site (joind.in also supports private events, see the website for more information).

    Once it is approved, make sure the timezone is set correctly by editing your event. For me this is Europe/Amsterdam, since I’m setting up data for the Dutch PHP Conference.

    If you are going to include information about the different tracks, either rooms or subject tracks, you can set these up now (if not, then skip to the next section). When viewing an event, if you are logged in and have admin rights on that event, you will see an “Event Admin” box. The “Event Tracks” screen will let you add, edit and remove the tracks for your event.

    Prepare Your Data

    I had the talks in a spreadsheet and I found this was a good starting point. Each row is imported independently so each one needs to contain all the information about the session. My spreadsheet had the following columns:

    • Date
    • Time
    • Track (string name matching the track you set up earlier)
    • Type (either “Social Event”, “Talk”, “Keynote”, or “Workshop”)
    • Speaker
    • Session
    • Abstract

    There was a lot of duplication here, for example lots of copied and pasted dates, but for each row to be evaluated separately, we need it to look like this. At this point I exported the spreadsheet to .csv format but joind.in currently only supports XML so I still had to built the format it could understand.

    Generate the XML

    I wrote a little script that processed my CSV file and spat out the XML that joind.in was expecting. There are a few pitfalls with this step:

    • I’m British, so my date formats assume dd/mm/yyyy
    • The import doesn’t support languages (see http://github.com/enygma/joind.in/issues#issue/91)
    • The script contains a function copy/pasted out of the joind.in codebase to handle the timezones calculation (because I already had it working once, I just stole it)
    • The first row in the spreadsheet is assumed to contain titles and is ignored
    • The script has a hardcoded timezone in it for Europe/Amsterdam

    By now you can guess this use-once script is a bit of a mess but in case it is useful I am uploading it here (if nothing else, I guess I might use it again!). I considered adding support for CSV files into joind.in itself (I’m a contributor) but I was short on time – if this would be useful to you or if you have any other comments on the process then add them here and I will do my best to reply!

    Resources

    • Conversion script for CSV files to Joind.in XML format (use at your own peril!) csvToXml.txt – change the file extension to .php
    • My original spreadsheet, in case an example is helpful talks.csv – this is the data for DPC 2010