PHP Frameworks Comparison Series: Zend Framework 2

development_6

The next entry in our Artemis Consulting Frameworks Comparison Series is Zend Framework 2 (ZF2). ZF2 was created by the web infrastructure company Zend Technologies. The first Zend Framework was released in 2006 and ZF2 was released in 2010. This is the next blog in our PHP Frameworks Comparison Series.

Our evaluation is based on criteria we established in our overview blog.

ZF2 is part of a large suite of products from Zend Technologies, including a web server, IDE package, certification exams for developers, and other tools for PHP and web application development.

This framework is solid and well-designed and thus, still popular among developers. Additionally, the fact that Zend Technologies has played such an important role in the development and promotion of the PHP language, makes ZF2 the default choice for many development teams.

Category 1: Core Framework design:
ZF2’s heavy use of dependency injection makes it a very modern and testable framework.
1. MVC support
ZF2 is based on the MVC design pattern, it separates Models from Views and the work is orchestrated through Controllers.

2. Thin controllers
It allows for the creation of thin controller methods and can do all the required actions outside the controller, using services and helpers.

3. Exception handling at framework level
ZF2 comes with a default error handler which catches all errors from the framework, but a developer can extend this functionality and/or create custom error pages to meet any specific requirements.

4. Inheritable configuration with respect to environments and installation across servers
The extent of ZF2 configuration files can seem endless. There is the global config, application config, environment specific configs, and module configs. Additionally, you must set up all of your controllers, models, mappers, services and many other types of objects in config files. This can be daunting, but, it does work well once you get the hang of it.

5. Overhead required to create basic module configuration
This is an area where I think ZF2 falls short. The aforementioned configs, plus other difficulties, means that it can be painful just to get a simple app up and running. You can see the steps in the official “Getting Started” to get a sense of what I mean.

6. PHP 5.5+ support
Supported.

7. Event management framework
ZF2 has the EventManager framework for this purpose.

8. Dependency injection support
Dependency injection seems to be one of the major architectural considerations in the creation of ZF2. Everything is injected, and this is part of the reason that everything must be specified in the configuration files.

9. Ease of bootstrapping and integrating with PHPUnit
ZF2 supports PHPUnit. In fact, unit testing is where the extensive configuration scheme and use of dependency injection pays off, because the dependency injection pattern is very testable.

10. UI templating support
You must create your markup in .phtml files. There is no specific templating language or scheme you need to know.

11. Command Line Interface (CLI) to execute applications
ZF2 has built in support for CLI. You must define console-specific routes and then call them by running the same ./public/index.php script that is used to serve web pages. This is an awkward way to run CLI scripts, but it does have the advantage of working exactly the same as the web routes, making it easier to test your CLI functionalities.

12. Support for manipulation of various data formats like JSON and XML
JSON and XML are fully supported.

13. Useful debugging tools
The ZendDeverloperTools module can be added to your application and includes many useful tools for debugging.

Category 2: Performance, scalability and redundancy:
ZF2 has all of the features for high performance, but that does not mean it renders web pages with any particular speed. If performance is a high priority, other frameworks are superior and ZF2 is not the one for you. .

1. Support for application caching
ZF2 supports caching using Memcache, Redis and Varnish.

2. Proven adoption on large projects
 Many large projects are known to be built on ZF2.

Category 3: Security:
ZF2’s has modules authorization, authentication and many other security pieces.
1. Modules for security such as authentication and authorization, and granular access controls
Some of the included security modules are Authentication, Captcha, Crypt, Escaper, Filter, InputFilter, Permissions, Math, and Validator.

2. Frequent security patching
ZF2 is actively maintained and security patches are released regularly.

Category 4: Instrumentation and troubleshooting support:
Third-party tools for instrumentation are robust.
1. Instrumentation metrics or accessibility at the method level
Xdebug can be used to achieve this.

2. Instrumentation metrics or accessibility at the SQL level
You must install the ZendDeverloperTools, this toolset is almost always utilized when usingZF2

Category 5: Database and Object-Relational-Mapping (ORM) support:

ZF2’s supports all major relational databases. Options for combining NoSQL with ZF2 are more limited. You do need to write more code for database access with ZF2 that some other frameworks.
1. Support for models that interact with relational databases used at the client, specifically MySQL and Oracle, and possibly MariaDB in the future
ZF2 supports PDO, and the drivers of relational databases that come with that. MariaDB works with the MySql PDO driver.

2. Support for fine tuning of the SQL used in the ORM
Included.

3. Support for interaction with NoSQL databases like MongoDB
Support for NoSQL databases does not exist out of the box. To pursue this route you will probably need to explore third-party modules.

Category 6: Community Support:
The information is out there. However, google searches do not always yield the most useful information, which can be frustrating.
1. Active maintenance and periodic releases
ZF2 is on its second major version and Zend Framework 3 is now in development. ZF2 is actively updated and maintained.

2. Large developer community, support and discussion forums
ZF2 definitely has a large community, although, I do find that Google searches of ZF2 questions do not yield the most useful pages. I recommend you bookmark the ZF2 class documentation which rarely shows up in the search results.

3. Ability to run on a wide variety of Linux and Unix platforms such as RedHat, CentOS, Ubuntu, and MacOS
Since it is a PHP framework, it can run on all supported operating systems

4. Well documented – up-to-date with current release
I find the way Zend organizes its documentation to be kind of frustrating, emphasizing tutorial-style narratives over the class reference material.

Overall, ZF2 is a good choice for your PHP application. The main advantage is that it is part of a larger suite of PHP products and it is being improved at a rapid rate. At the same time, it is not a good framework for rapid prototyping or getting started quickly.