Category: PHP

Opening keynote by Andrei Zmievski at DPC09 – The evolution of PHP

Purpose of the entry

On Friday June 12th 2009 the Dutch PHP Conference started with a small introduction by Cal Evans, director of PCE at Ibuildings and previous editor-in-Chief of DevZone at Zend, Inc.
Cal welcomed us all at the third edition of what will become one of the major players concerning php conferences in Europe. The conference itself is packed with great talks on various subjects regarding programming. From the novice topics like the excellent talk from Ben Ramsey on “Grokking the REST Architecture” to the more advanced like “Trees in the Database: Advanced Data Structures” by Lorenzo Alberton. The latter I could unfortunately not attend, a man has got to make choices. I was attending Ben Ramsey’s second talk on REST because the first one was really really interesting. I did not have to choose which opening keynote to attend. There is only one per day and the first day was opened by Andrei Zmievski. He is a real entertainer. He brought the evolution of PHP, the new features in PHP 5.3 and PHP 6.0. He also said what PHP 7.0 will not be.
In this entry I will give an overview on the talk given by the main guy responsible for the official PHP releases.

Overview

  1. What is PHP
  2. PHP is mature and version 5.3 will arrive shortly
  3. PHP 6.0 is coming and with it Unicode and traits
  4. PHP7.0
  5. Resources
  6. Closing notes

What is PHP

PHP or Hypertext PreProcessor is a dirty language with a very low learning curve. This has been the success of the dominating web language. It is dirty because it was build upon release upon release. Never able to clean up some errors made in the beginning when the language was starting to evolve. This resulted in some function parameter inconsistencies and design issues that could have been done a different way. Because PHP took features from other languages it is a mix of various things. PHP is a ball of nails, it is not a full breed, but more like a mutt. But you got to love the mutt. It works brilliantly and does what it needs to do. And with every release it becomes more and more mature, more and more beautiful. Mutts often are stronger than full breeds also…

PHP is mature and version 5.3 will arrive shortly

Within a couple of weeks the long awaited PHP 5.3 version will be released as stable.
Like PHP 5.1 made a huge leap with the PDO integration so will 5.3 with namespaces. Andrei made some jokes about the decision to use backslashes as the namespace symbol. He did this with mails send to the mailing list and I must say it was hilarious. The message he wants to give to the community is: Yes we have used the \, stop whining about it and start adopting it. You have no choice. Decisions have to be made and we, the PHP Core developers have made ours. Personally I am sure namespaces will change the way programmers and framework architects develop their applications. Maybe not immediately but over the years they will.
Things like lambda functions and closures are also supported and I am positive people will start to adopt to this new functionality right away. I know I will.
As I said before PHP is a mutt and it has adopted a lot of features from other languages. Java is one of them. The tradition is continuous and with the introduction of phar files I am positive a lot of deployment will change. Phar allows you to pack your entire project into a single file, pretty much like a tar or zip file. You can browse and include these files from the Phar file from within your code as if it was a normal directory on your filesystem. You can also execute your application from within the file entirely. As you can imagine this gives big benefits on deployment where some files always have to be uploaded as a single pack to ensure the sequential uploading of files to avoid the resulting breaking of the application for a period of time. Or the way libraries and common applications like phpMyAdmin are distributed.
If you want to know more about lambda, closures, phars and namespaces there are some great resources available and I will give you a list at the end of this article.

PHP 6.0 is coming and with it Unicode and traits

Traits is PHP solution on the multiple inheritance problem. There is no diamond issue here and still you can use the functionallity of multiple classes from within a class. You will still be limited to inheritance from a single parent, and this is a good thing, but you can import (dynamically copy/paste) methods from a secondary or n+ other classes. Unicode will solve the internationalization problems, problems with some string functions and even allow chinese programmers to program in chinese. Do not expect Andrei or me for that same matter to debug such applications. 🙂

PHP7.0

PHP7.0 is coming and it will offer lots more of functionality and great stuff. What it will be nobody knows (maybe some do?), but what is known is that it will not be PHP designed from scratch. A version polished to perfection. The ultimate clean language. Such a language does not exist and if someone is eager to build it, it will not be called PHP. PHP is a powerful tool. If used in experienced hands you can develop applications with it that will astound everybody. Go and use PHP. And if you are using PHP love it, cherisch it and welcome the changes.

Resources

Closing notes

Andrei Zmievski is a wonderful speaker with lots of charisma. With his opening keynote he awoke my interest of using all the new functionalities future releases of PHP will offer. As a core PHP developer and leader of the PHP-GTK project he was not afraid to make various jokes on himself, the community and PHP. Which made the talk very lighthearted and easy to digest. One of the cool stuff was when he pointed to an ini setting called y2k_compliance in PHP3 which did nothing but made you feel safe. Like a placebo for PHP. That was so much fun!
His talk made me keen on using all the new PHP 5.3 features and made me look forward to using PHP 6.0. And with me a lot of other developers were feeling good at heart and ready to attend all the talks the dutch PHP conference had to offer. The stage was set to be one of the best content wise conferences I ever attended.

Happy coding from sunny Belgium,
Nick Belhomme

Zend Framework 1.8 Workshop at the Dutch PHP Conference 09

Purpose of the entry

On Thursday June 11th 2009 I attended a workshop on the very (dare I say the most) popular PHP framework: Zend Framework (ZF).
I will share my experience in this entry and try to give you a quick overview on the tips I found most interesting.

Overview

  1. General experience
  2. Components
  3. Resources
  4. Closing notes

General experience

If you follow Matthew Weier O’phinney’s blog and career you already know he is a real authority in his field. Today it is the Zend Framework. As the project leader at Zend Technologies, he is doing development and coaching his team towards an ever expanding and more stable framework. The workshop itself was not really a workshop at all but an extended presentation lapping several hours. This means that during this presentation no real hands-on coding was done by the attendees.

Matthew gave a high level presentation on the most common (and some new) components. Whenever an attendee had a question he was more than willing to explain it to a deeper detail. This makes him very
approachable and someone who is eager to help.

Components

Matthew discussed the new components Zend_Application and Zend_Tool. Both new in Zend Framework 1.8 and both seem to offer when understood completely an entire new user experience on how you setup your ZF projects. Zend_Application offers you a way to do bootstrapping on a more uniform way and Zend_Tool offers you tools to do the scaffolding for you. If you want more info on both of them please visit the official documentation or take a look at the presentation which I included at the end of this entry. Of course Zend_Auth and Zend_Acl were also discussed and in such a matter that it deviated from the way it was best practice in ZF 1.6 as described in the marvelous Zend Framework In Action book by Rob Allen. If you do not yet own this book hop over to Rob Allens webpage, Amazon or wherever you can get your hands on it. At the moment it is still one of the best books about ZF and offers some very valuable tips on the subject. The deviation illustrates that a framework like every other piece of code is organic and has the tendency to lead its own life. Which is actually a good thing, “grow or die” remember?

One of the main tips I got from the presentation was the use of the DAO (Data Access Object) principle.
Instead of adding your data access directly into your model you should add a DAO as a layer between your model and data resource (database, xml, csv, …). This way if you want to switch from a database to a webservice (think of scalability), you do not have to rewrite every single model but only the DAOs. If you want to know more about scalability I will be doing an entry on this based on the incredible presentation done by Eli White, PHP Community Manager & DevZone Editor-in-Chief at Zend Technologies.

Zend_Form was also covered and Matthew explained that it would be in the project it’s best interest to set the decorators in the view instead of the controllers/models. Decorators are a part of the display and thus should be handled in the view. He showed a practical example of how to style and display form elements separately in the view instead of doing the <?php echo $this->form; ?>. This is done by simply accessing the form element through the properties of the form. <?php echo $this->form->username; ?>

Of course other useful tips were shared in this presentation and I stronlgly encourage you to attend one of these whenever and wherever you have the chance to attend one. Because of the purpose of this entry I am not going any deeper into the subject. You can find Matthews presentation online .

Resources

Closing notes

I hoped you enjoyed reading this entry as much as I wrote it. I surely would recommend adopting a framework to your skills. ZF is a smart choice and the community is very very strong. In todays world if you do not know one or 2 of the major players out there like ZF or Symfony you are sure to run into trouble sooner or later regarding employment. For a more direct access to the community attend workshops like the one I just described or visit the #zftalk irc channel on irc.freenode.net

Sunny greetings from Belgium,
Nick Belhomme

Using Zend_Form, Zend_Config_Ini And Zend_Db_Table

Ok I am going to write a little bit about Zend_Form.
Yes I know a lot of small tutorials already exist but this one can
show you another trick 🙂

My prefered way of using Zend_Form is to use it with a config.ini file.
It gives you a nice overview of special settings in a structured way. I love that.

One thing the manual does not explain is how to use it in addition with for instance dynamic population/value setting of a Zend_Form_Element object.

Say you have a select field that needs population. You cannot do that manually in the config file every time the database gets updated. There should be a better way. And actually there is.

Small example stripped to the bare minimum follows:

formConfig.ini

 [time]

time.action = "/time/save"
time.method = "post"
time.accept-charset = "utf-8"

time.elements.deliverytime_id.type = "select"
time.elements.deliverytime_id.options.label = "Delivery Time: "

time.elements.createsubmit.type = "submit"
time.elements.createsubmit.options.label = "create new"

Above we have a regular config.ini file ready to be parsed with Zend_Config_Ini.
For more information on how to use this with Zend_Form see Using a Zend_Config object

Time.php

<?php
class Time extends Zend_Db_Table {
    protected $_name = 'time';
}

Time.php is the Model for our time Table. This way we can easily do table manipulation without writing
any sql. This for potential portability to another database and your convencience.

TimeController.php

<?php
class TimeController extends Zend_Controller_Action {
    protected $time;
    protected $formTime;
    
    public function indexAction() {
        $this->view->formTime = $this->formTime;
    }
    
    public function init() {
        $this->time = new Time();
        $formConfig = new Zend_Config_Ini(APP_CONFIG.'/formCms.ini', 'time');
        $this->formTime = new Zend_Form($formConfig->time);
        $this->setupDeliveryTimesInFormSelect();
    }
    
    private function setupDeliveryTimesInFormSelect() {
        $select = $this->formTime->getElement('deliverytime_id');
    
        $deliveryTimes = $this->Time->fetchAll()->toArray();
        foreach($deliveryTimes as $timeOption) {
            $select->addMultiOption($timeOption['id'], $timeOption['time']);
        }
    }
}

This is a regular Controller. This is just stripped example code just to make you understand everything with more clarity. The key is in setupDeliveryTimesInFormSelect(). Here we get the form element from our $this->formTime.  It was already generated in the init() function.
Because all things are static in the config file we are going to populate it with options using the addMultiOption(). The values that are being used in the foreach loop are returned by a Zend_Db_Table object generated in Time.php.

The result of this code if you render your index view is a form with a submit button and a select box with options/values pairs set straight from a database. Because it is a select,  the submitted values are compared to the values in the form. Other form element types like text etc should have their submitted values validated and or filtered. You can find plenty of examples on how to set those options in the config.ini file on the net.

Happy Coding

Nick Belhomme
Your PHP5 Zend Certified Engineer

phpGG Frontend Special was da bomb

Hello again,

Yesterday I attended the phpGG Frontend Special  , phpGG first great conference and I must say it was very good organized. I had to be on the road for more than four hours but it was worth every second of it.

Like on most conferences you were welcomed with your preferable drink, for the record mine is orange juice. I saw a lot of net workers drinking milk. 🙂 After some networking/ chitchatting  the presentations began right on time.

The presentations were professionally introduced by Stefan Koopmanschap and Kana Yeh and were all on the topic of front end.

The first presentation was from Bram Veenhof about MS Silverlight. It was interesting but not really PHP oriented.

The second one speaker was a charismatic speaker with great humor and very much knowledge about the Adobe Flex and Air platforms, Mihai Corlan.

He was able to grab my interest with live demos and coding examples. In a matter of minutes he had a working application using Flex and PHP. Awesome. I really see this technology used in one of my next CMS projects. He explained about datagrids and how flex uses them to interact with a Mysql Database through PHP on a different or same server.

After so much interesting information it was time for a lunch break and I spoke with Mihai and he explained first hand the new technology behind the Text Layout Framework in Flex 3.2 or AIR 1.5. It looks great, I urge you to check it out if you are interested in anything Flash, Flex or Air related.

After a sandwich or two it was time to have presentations introducing some user groups.  Juliette Reinders Folmer introduced  PHP Women ,  Sander van Lambalgen introduced Fronteers and of course the group phpGG, frontend special organizer itself, was introduced by Stefan. He even threw in some surprise gifts. Including several elephpants, ZCE study guides and even two tickets to the upcoming PHP Conference in London.

Now my favorite presentation took of. Ibuildings own Javascript evangelist Boy Baukema. He talked about of course Javascript and what made it interesting for me was the fact that he made comparisons between upcoming new features in PHP 5.3 and already existing features in Javascript like Lambda functions and Closure. I will post a link towards the presentation soon.

Robert Jan Verkade founder of Eend.nl  talked about why PHP developers should be nice to frontend and visa versa. Personally I do not have any bad experiences on this subject but I can imagine a lot of developers do. He said communication is key. Isn’t this so true for all parts of life! But if communication is faulty on your work floor he spoke about some key principles what you can do to minimize conflicts.

And that is a wrap.  I would like to thank all the speakers and the organization phpGG for  making my Saturday a very good one. I hope to see more of these days organized in the future. If not for the great presentations, than for the wonderful networking you can do. It is always fun to see new and familiar faces.
I hope to be able to post links to the presentations somewhere this week. In the meantime you can checkout Flickr, there are some pictures definitely going to be posted there under the tag: phpggfs

Warm winter greetings from Belgium,
Nick Belhomme
Your PHP5 Zend Certified Engineer

[UPDATE]

Ok as promised  here are the slides:
* Flex and AIR for PHP programmers by Mihai Corlan

*  Javascript: 8 Reasons every PHP developer should love it by Boy Baukema

* phpWomen