4.0 Upgrade Guide

Before attempting to upgrade to 4.0 first ensure you have upgraded to 3.8. Thenenable deprecation warnings:

  1. // in config/app.php
  2. 'Error' => [
  3. 'errorLevel' => E_ALL ^ E_USER_DEPRECATED,
  4. ]

Then, incrementally fix the deprecation warnings your application and itsplugins emit.

Upgrade to PHP 7.2

CakePHP 4.0 will require PHP 7.2. Upgrading PHP before updating CakePHP isrecommended to reduce risk.

Use the Upgrade Tool

Because CakePHP 4 adopts strict mode and uses more typehinting, there are manybackwards incompatible changes concerning method signatures and file renames.To help expedite fixing these tedious changes there is an upgrade CLI tool:

Warning

The upgrade tool is intended to be run before you update yourapplication’s dependencies to 4.0. The rector based tasks will not runcorrectly if your application already has its dependencies updated to 4.x orPHPUnit8.

  1. # Install the upgrade tool
  2. git clone git://github.com/cakephp/upgrade
  3. cd upgrade
  4. git checkout 4.x
  5. composer install --no-dev

With the upgrade tool installed you can now run it on your application orplugin:

  1. # Rename locale files
  2. bin/cake upgrade file_rename locales <path/to/app>
  3.  
  4. # Rename template files
  5. bin/cake upgrade file_rename templates <path/to/app>

Once you’ve renamed your template and locale files, make sure you updateApp.paths.locales and App.paths.templates paths to be correct.

Applying Rector Refactorings

Next use the rector command to automatically fix many deprecated CakePHP andPHPUnit method calls. It is important to apply rector before you upgradeyour dependencies:

  1. bin/cake upgrade rector --rules phpunit80 <path/to/app/tests>
  2. bin/cake upgrade rector --rules cakephp40 <path/to/app/src>

Update CakePHP Dependency

After applying rector refactorings, upgrade CakePHP and PHPUnit with the followingcomposer commands:

  1. php composer.phar require --update-with-dependencies "phpunit/phpunit:^8.0"
  2. php composer.phar require --update-with-dependencies "cakephp/cakephp:4.0.*"