r/PHPhelp • u/zephead98 • Sep 28 '26
App Written in PHP 4.2
How big of a task am I looking at, lol?! I can use sed to recursively go through files and replace old syntax with newer syntax where possible. The app has about 110 files, most less than 100 lines (including comments).
There used to be this neat little php program called ez_results where you could query the DB and feed the results to ez_sql and it would build this nice table with the results (including navigation buttons). I would like to find a replacement for that unless PHP 8.2 (what I am working with) has such a feature.
Thank you and no laughing please! I am digging through a PHP 8.2 book for some answers, the syntax of 4.2 is wildly different!
11
u/miqrogroove Sep 28 '26
What is "wildly different"? I often find PHP 4 code is frustratingly compatible with PHP 8, even when it was written wrong in the first place.
22
u/AlFender74 Sep 28 '26
For something that small, approx 100 files, mostly approx 100 lines, I'd just hook it up to a modern PHP and Database and work through the issues.
13
u/mrdarknezz1 Sep 28 '26
If you get it to 5.3 you can use https://getrector.com/upgrade/php
12
u/Hour_Interest_5488 Sep 28 '26
Cannot AI handle that? You can follow classic refactoring process - create autotests, refactor until tests are green. Are are awesome!
4
u/Aggressive_Ad_5454 Sep 29 '26
Download the JetBrains IDE called PhpStorm. It has a 30-day evaluation. It will help you fix up your code.
You can set the language level to, I dunno, 5.6, and it’ll highlight the stuff you need to fix.
Then to 7.4 and repeat.
Then to 8.1
3
u/latro666 Sep 28 '26
What does it do? How important is it? That old for that long would suggest anything you blanket change could have a lot of legacy workflows that might change. Could even get it running fine only to find out some date format check is wrong or a null should be a 0 or something and its all too late.
I'd document and work all that nuance out first with test plans etc. Updating the code will probably be the easy bit.
3
u/dabenu Sep 29 '26
I guess that's like what, 20+ year old? What's so special about this ancient app that makes it even worth upgrading? As opposed to using anything else...
I'm pretty sure I'd rather start from scratch than touch such old code at all. But if you really have to, I'd just prompt AI "analyze this php4 app, recreate it in php8". Might not be perfect, but a much better starting point than php4.2
3
u/flarian-aux Sep 29 '26
Use rector, use php-cs-fixer, use phpstan, use any coding agent. Should be an easy thing. :)
2
u/magicmulder Sep 28 '26
Damn and I thought having to migrate a 5.2 app running on Symfony 1.2 was dealing with old code…
2
u/Ok-Article-885 Sep 28 '26
Is this still working?
2
u/Big-Dragonfly-3700 Oct 05 '26
There are changes in security (magic quotes), error handling (exceptions), error response (notice, warning, and fatal error level changes), register_globals/superglobal variables, removed features (mysql_ extension), and backward incompatible changes that have occurred since php4.2. You will have to go through the code, in context, and address each of these things.
The correct way to do this would be to read the php documentation migration appendixes. Some of the changes (exceptions, prepared queries) will actually reduce the amount of code required to accomplish a task.
2
u/PuffPuff74 Sep 28 '26
At this point, rewrite it
2
u/l3msip Sep 29 '26
Do you want to learn something, or do you just want to update the app?
If this was a task I had to accomplish (25yrs exp php dev, so not looking for a learning project), I would:
Pull the code down onto my local machine Create a local git repo to track changes (presuming one doesn't exist, since php 4.2 was released 3 years before git existed). Open the project in phostorm, and launch Claude code from the terminal.
Switch to fable 5.1, explain you plan to rebuild the app in modern (php 8.4+) php, but need to start with through documentation, focused on functionality, written as mark down in the docs folder.
Go make a coffee
Come back and read the docs, cross check against your personal knowledge and the live app.
There is a very high chance given the size of the project you know have solid docs covering the full functionality, with a number of preexisting bugs and edge cases documented.
I would then manually confirm the docs against the live app, cross check any bugs or edge cases with any colleagues (long running bugs often become features), and ask the llm to write up a product spec and roadmap for rebuilding the app in a modern php stack (for me Laravel 13).
Chances are you can have a full rebuild done in a week, with a proper test suite
2
u/kaizap Sep 29 '26
This is what AI is born for 😄
1
u/Alone_Leading_4685 8d ago
core PHP still doesn't have a built-in table generator with pagination, you'll have to write a simple loop with PDO and some basic offset/limit SQL for that part. With files that small though, rewriting the queries cleanly with prepared statements shouldn't take too long.
1
u/PrizeSilver5005 Sep 29 '26
If I had a snapshot.of some of the code (non prop'tary/ip exposure of course), I'd love to take a look and help, ngl, hahaha, I started writing php when 5.1 was just becoming a thing and wrote a decent amount of procedural and just learning oop (which 5.3 started to actually move in that direction) with 5.2 and really got dirty with 5.3, creating a blog/minimal cms (at the time was a huge accomplishment for me as I was a "lone wolf and reading tons of books and docs of the time) that I used successfully for a small start up through ~2016 or so when I decided a rewrite to learn php7, and it was a ton of intellectual fun! The cms/blog I wrote was in spite of wp at the time because I hated it the 2 times I tried to use it and it was literally all about personal education for myself and was when - against all haters of php then (likely way worse than now) - I decided php was my choice for backend development and I went in many directions with it, even though mysql/apache stayed my day job choice, was just an awesome experience. Sometimes I miss those days of real problem solving that is soooo taken for granted these days. Seeing that code and how to modernize it is always fun brain work to me! Note - none of this comment is a joke, it was a fun experience learning and it opened up a ton of doors that I'd have never even thought of. I think I was a sophomore in college when 4.2 was the latest and greatest of php, haha... I'm interested
1
u/Intrepid-Ad-2306 Sep 29 '26
honestly, it’s not that large a task with such tiny files. i’ve been using php since… well, i remember migrating perl cgi stuff to php when it was very new. most of the changes in php have been surprisingly backward-compatible. yes, you’ll find some syntax rewrites but a lot of things just work. maybe not the best way of doing things now but often still functional.
if you’re looking for an excuse to rewrite it from scratch, go for it. but, if all you want is to make it work in modern php, set yourself up a testing environment and open it in an editor like zed with inline linting. a hundred-line file probably won’t take you more than a few minutes to go through and fix the errors. sed is likely to introduce far more trouble than the time it’ll save.
i wouldn’t be surprised if many of those files just run.
1
u/HyperDanon Sep 29 '26
I think i would upgrade version by version, 4.4, 4.5, 5.0, 7.0, 7.1, 7.3, etc
1
u/Tomas_Votruba Sep 30 '26
You're lucky it's procedural PHP (no fw, no deps, pure PHP). Agents will be able to handle this in couple iterations, 2-6 hours, depending on how you approach it step by step.
Ask Claude Code/GPT Codex to upgrade, first to PHP 5.3, then 7.0, then 7.4, 8.0 and 8.4. Make a PR for each of those and you'll see the new syntax changes clearly from diffs.
Little work, lot of knowledge
1
u/peperinna Sep 30 '26
Hicimos un experimento hace año y medio con IA, que no tenía el mismo poder y nivel que hoy, y nos actualizo algo de 5.6 a 7.3 bien, ya a 8 cometía muchos errores. Eran unos 90 archivos, y funcionó bastante bien. Creo que justifica pagar 100 uds a Claude, sale más barato que un programador, luego haces un buen test.
0
u/CenturiesAgo Sep 28 '26
Doesn't sound so insurmountable, probably easier to start from scratch though.