A free and open-source book on Zend Framework for beginners

1.12. Differences with Zend Framework 2

For readers who have an experience in Zend Framework 2, in this section we'll give some information on what has changed in Zend Framework 3.

Below, the main technical differences between ZF2 and ZF3 are presented:

1.12.1. Backward Compatibility

ZF3 is an evolutionary release, so backward compatibility is preserved in most cases. However, some migration work still has to be done if you used ServiceLocatorAwareInterface across your code (which you probably did). In ZF3, this interface has been removed, and now all dependencies must be injected through factories. So, you'll have to create factories for the most of your controllers, services, view helpers and controller plugins.

1.12.2. Components

In ZF2, components were stored in a single GIT repository. In ZF3, components are stored in multiple GIT repositories, one repository per component (for example, zendframework/zend-mvc, zendframework/zend-servicemanager, zendframework/zend-form, etc). This allows to develop and release components independently of each other.

Components are even more decoupled than before and have minimum dependencies on each other. Zend\Mvc component has been divided into several ones. For example, routing functionality has been moved to new Zend\Router component.

You are now recommended to specify individual component names your app depends on in composer.json, although it is still possible to depend on zendframework/zendframework package, which is a meta package installing all available components.

1.12.3. Component Installer

In ZF3, a special Composer plugin called component installer was introduced. It allows to install components as ZF modules. It injects information about the component into the application configuration file.

1.12.4. ServiceManager and EventManager Performance

ZF3 developers did a great job improving performance of Zend\ServiceManager and Zend\EventManager components. They are now about several times faster than before. The disadvantage is that you now have to do some migration work to use the new functionality. Controller and service names are now recommended to utilize the PHP 5.5 feature called ::class. For example, if previously you registered your controller as Application\Controller\Index, now you will register it as IndexController::class. If previously you registered service names as you wished, now you are recommended to do that using ServiceClassName::class. Read the documentation for Mvc component for additional information.

1.12.5. PSR-4

In ZF2, the recommended directory structure was PSR-0, while in ZF3 it is PSR-4. This requires some (small) migration work.

1.12.6. Middleware

Zend believes that the future of PHP is in middleware. "Middleware is, quite simply, code sitting between an incoming HTTP request, and the outgoing HTTP response." Now you can register a middleware listener in an MVC application.

1.12.7. Focus on Documentation

Now each component repository contains its own documentation. Documentation is now in Markdown format and has become better designed.