Innovate faster and cut risk with PHP experts from Zend Services.
Explore Services
Beginning to advanced PHP classes to learn and earn global certification.
Help me choose >
Explore Training
Submit support requests and browse self-service resources.
Explore Support
Note: this workflow is a general guide. Use your judgement based on your specific use case.
Set up two environments to run the code: the current version, and the one to which you want to upgrade. We'll refer to these environments as "baseline" and "upgrade" respectively. They should be as similar as possible, except for the PHP version. You may encounter problems at this stage:
Enable all error reporting, including notices. This is important because many of these notices will become warnings or even fatal errors in newer PHP versions. By suppressing notices, you would only make it harder to debug compatibility issues.
A great way to find incompatibilities is to use an automated tool called PHPCompatibility. It will scan your code and will give you a comprehensive report of the problems that it has found.
If you run it with the -s flag, then the report will also give you the names of the sniffs, which your can use to navigate the list of incompatibilities.
-s
For example:
vendor/bin/phpcs -s
will output a report with the sniff name in parentheses:
(PHPCompatibility.Operators.ChangedConcatOperatorPrecedence.Found)
Please note that despite PHPCompatibility being an amazing tool, it does not replace thorough testing. It does not guarantee to detect every possible problem, nor can it vouch for the correctness of your fixes.
Tip: it would be prudent to write an automated test suite before undertaking a PHP upgrade; at the very least, a high-level acceptance test suite would be invaluable to ensure a successful upgrade.
If some issues went unaddressed despite a successful upgrade, you may choose to ignore them in the code analysis. You can achieve that by creating a phpcs.xml file such as this one:
phpcs.xml
<?xml version="1.0"?> <!-- see: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset --> <ruleset> <!-- Allow specific extensions, as to not scan files that don't have any PHP in them --> <arg name="extensions" value="php,inc,html,tpl"/> <autoload>vendor/phpcompatibility/php-compatibility/PHPCSAliases.php</autoload> <!-- Exclude a folder --> <exclude-pattern>../.svn/*</exclude-pattern> <!-- Exclude a file --> <exclude-pattern>../classes/myUser.orig.php</exclude-pattern> <!-- Ignore empty files, should you be required to keep them --> <rule ref="Internal.NoCodeFound"> <severity>0</severity> </rule> <!-- Ignore mixed line endings, should fixing them cause other problems --> <rule ref="Internal.LineEndings.Mixed"> <severity>0</severity> </rule> <!-- Disable a sniff --> <rule ref="PHPCompatibility"> <exclude name="PHPCompatibility.Miscellaneous.RemovedAlternativePHPTags"/> </rule> <!-- Disable a sniff, but only for certain files --> <rule ref="PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore"> <exclude-pattern>../lib/pear/PHPUnit-3.4.9/*</exclude-pattern> </rule> </ruleset>
Increase security and cut risk by simplifying PHP application upgrades and migrations.
Long Term Support buys organizations time to migrate.