So you have decided to upgrade to v5! Congratulations!!
Phalcon v5 contains a lot of changes in components and interfaces. Upgrading is going to be a time-consuming task, depending on how big and complex your application is. We hope that this document will make your upgrade journey smoother and also offer insight as to why certain changes were made and how it will help the framework in the future.
We will outline the areas that you need to pay attention to and make necessary changes so that your code can run as smoothly as it has been with v4. Although the changes are significant, it is more of a methodical task than a daunting one.
Phalcon v5 supports only PHP 7.4 and above. PHP 7.4 active support expired roughly a month before the release of Phalcon 5, but support for Security patches etc. will continue until November 2022. After that time, we will drop support for PHP 7.4 also.
Since Phalcon 4, we have been following the PHP releases and adjusting Phalcon accordingly to work with those releases.
Phalcon requires the PSR extension. The extension can be installed with PECL:
pecl install psr
If you do not wish to install it with PECL, you can download and compile OSR from this GitHub repository. Installation instructions are available in the README of the repository. Once the extension has been compiled and is available in your system, you will need to load it to your php.ini. You will need to add this line:
Alternatively some distributions add a number prefix on ini files. If that is the case, choose a high number for Phalcon (e.g. 50-phalcon.ini).
Phalcon can be installed using PECL.
pecl install phalcon-5.0.0
It is important to check your php.ini file (both for your web server and CLI) and make sure that phalcon is loaded after psr. Your php.ini should look something like this:
Download the latest zephir.phar from here. Add it to a folder that can be accessed by your system.
Clone the repository
git clone https://github.com/phalcon/cphalcon
git checkout tags/5.0.0 ./
Check the module
php -m | grep phalcon
One of the biggest changes with this release is that we no longer have top level classes. All top level classes have been moved into relevant namespaces (with the exception of Phalcon\Tag). For instance Phalcon\Loader has been moved to Phalcon\Autoload\Loader. This change was necessary for the future expansion of the project.
The Loader component has been moved to the Autoload namespace. Some method names have been changed and new functionality introduced.
__construct(bool $isDebug = false)
The constructor now accepts a boolean, which allows the loader to collect and store debug information during the discovery and loading process of files, classes etc. If the variable is set to true, getDebug() will return an array with all the debugging information during the autoload operation. This mode is only for debugging purposes and must not be used in production environments.