ZendCon 2010 Day #1

A new approach to object persistence in PHP by Stefan Priebsch

I went to this talk hoping to get some more information about MongoDB combined with object persistence. It turned out that the system Stefan was supposed to talk about was not yet finished, so instead he talked about generic ways of achieving object persistence. I believe parts of the code that he used in his slides is taken from the system he was supposed to talk about.

He also mentioned a couple of nasty tricks that should never be used in production, like creating an instance of a class without running the constructor (using unserialize) and making private and protected properties accessible using Reflection.

Lazy loading was also mentioned which is very important when dealing with ORM systems. Most of the techniques he talked about was pretty straight forward and included nothing new.

484 Days of PHP 5.3 and What Have We Done (And Learned)? by Ralph Schindler

This talk was about some of the new features that came with php-5.3, like:

  • __invoke magic method
  • late static binding
  • closures
  • namespaces

Of these features I have only used late static binding and closures. While I do get the point of using namespaces I had not found a good use for the __invoke method until this talk! I use Zend Framework for some private projects and some things that have annoyed me with the view scripts is how the view helpers are invoked. Usually you just do something like:

<?= $this->someHelper( ... ) ?>

With the __invoke magic method you can call an object directly as if it were a function, as long as it has implemented the __invoke method of course:

<?= $someHelper( ... ) ?>

Not a big difference but this is only one example of where to use it.

Late static binding is especially nice when it comes to the singleton pattern. Now you can have an abstract singleton class that other singletons can extend, and you don’t have to copy&paste the getInstance() method all over the place. The abstract class can be implemented like this:

abstract class SingletonPattern {
    static protected $instance = array();
    protected function __clone() {}
    protected function __construct() {}
    static public function getInstance() {
        $className = get_called_class();
        if (!isset(static::$instance[$className])) {
            static::$instance[$className] = new static;

        return static::$instance[$className];

Other classes can then become singletons by just extending this class:

class SomeClass extends SingletonPattern {}
class SomeOtherClass extends SingletonPattern {}

To create instances of these classes you do:

$object = SomeClass::getInstance();
$otherObject = SomeOtherClass::getInstance();

Best Practices in deploying PHP applications by Shahar Evron

This talk included some interesting ways of deploying code on production servers. From the simplest svn up on a working copy in production, to more complex techniques such as rpm packages and rsync. At work we mostly use working copies on production servers which makes it very easy to update and to roll back to older revisions if the update causes problems. We also use rsync but mostly for static content, and not PHP code. We have a pretty simple setup so no need for complex deployment routines.

Shahar also mentioned deployment scripts that can be created and used if many manual operations is needed to update the codebase on your production servers. The deployment script should also support rollbacks whenever possible.

Unit testing after Zend Framework 1.8 by Michelangelo van Dam

Michelangelo talked about how to organize and test Zend Framework applications. I also learned that PHPUnit-5.3.0 introduced support for using an xml formatted mysqldump file for use with the database extension. I’ll be sure to try that out pretty soon! Other important tips was some pretty obvious (but good) ones:

  • Test the most critical parts of the application first
  • Make sure to write tests after bugs have been fixed
  • Learn about exploits against other sites and make tests for them so that your site is safe

Memcached, the Better Memcache Interface by Ilia Alshanetsky

I did not learn much new stuff in this talk. At work we use the old Memcache extension, but I have already written some components that use the new Memcached extension, so hopefully we will be able to try that out pretty soon. There are some interesting features in this extension, like result and read-through cache callbacks. If you have a pool of servers you also have the opportunity to map certain keys to specific servers as opposed to just storing a key value pair on a random server in your pool.

Other than that the new extension behaves much like the old Memcache extension.

And that was that. The first day of the conference have been very good! Talked to some talented people and listened to even more talented people. Looking forward to more talks tomorrow!

This entry was posted in PHP, Technology and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s