Upgrade PHP Code from 7.4 to 8.2

A while back, I created a PHP object-orientated web app that takes attendance and absence of people at a convention and also lets you create users, login, view records and more.

The problem is that my code was originally written in PHP 7.4 which has ended support and I need to upgrade my code to PHP 8.2 (the current latest version). I have no idea how difficult that is to do, though I’ve seen ways you can use automated script that reads your code (e.g. Rector), however I have no idea where to start with that.

My code also does not run on a PHP framework. Since I have little to no security measures in my code, I’m thinking it would be better to put it in one, though I’m new to frameworks and not sure which to use. I’ve heard of Laravel being the most popular one, but it seems a little complicated to me.

What do you guys think I should do? Any advice would be greatly appreciated.

Well first, going from 7.4 to 8.2 may not be trivial and will depend on what your code uses and how well it was coded back in 7.4. Largely if it follows good practices in 7.4, it will be much easier to upgrade.

Second, moving into a framework will probably require a rewrite of 70-80% of your code. Again, depends on what your code is, but I would consider it more of a rewrite than not.

Third, before you figure out anything, you should do a audit of everything your site has. How many pages are you talking about here? How many lines of code? How well was it coded? Was it coded by you with little knowledge of PHP? Do you know a lot more now? Do you have a budget for this? Can you possibly hire a coder to simply look over the code and see if it requires a little or a lot of changes?

All these questions are going to govern what you need to do next. If your site is simple, followed great coding best practices back in the day, coded by someone who had experience, moving to 8.2 is going to be a lot easier than if it was coded by you with 1 week of experience, is 20k lines of code and by no means is following good practices.

Do the audit or have someone do an audit first and that way you can get an idea of what you are dealing with first before making changes going forward.

As long as your code isn’t using any previously deprecated, now removed, features, it may run as is under the latest php version.

Php has migration sections in the documentation that list the backward incompatible changes between major versions that you would need to make sure your code is not using - https://www.php.net/manual/en/appendices.php

Just using a framework doesn’t provide security. You can write perfectly insecure code using one, the same as without using one. Writing secure code requires using data safely in whatever context it is being used in.

The biggest noticeable one would be that PHP no longer supports dynamically typed properties. There is however a workaround which is to append the #[AllowDynamicProperties] attribute to your classes that use dynamic properties. Use #[\AllowDynamicProperties] if you’re using namespaces.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.