Before you talk about the difference, you need to know why codeigniter 4 release was a must, between the stable version of codeigniter 3 and codeigniter 4, it took around 5 years.
in that duration many things on internet are changed, Many new frameworks are released with latest technologies, PHP version upgraded to 8, MySQL discontinued and many more changes happen.
Meanwhile Codeignier failed to maintain the popularity, Codeignter went from top most framework to least framework and changing into the obsolete framework. The first stable version of CodeIgniter was released by EllisLab on February 28, 2006 and they decided to continue development to release codeigniter 4. Codeigniter 4 was released On February 24, 2020, on the birthday of Jim Parry who was the project lead of Codeigniter 4 and died on January 15, 2020. Now let's come to differences.
Differences in version 4
1- Support for PHP versions
CodeIgniter 3 was working with 5.6 which is already outdated while codeigniter 4 requires minimum PHP version 7.2 or above.
2 - Directory organization
huge change in directory structure. codeigniter 4 directory structure is organized in 5 folders : /app, /system, /public, /writable, /tests while codeigniter 5 has folder structure: /app, /system
3- Use of namespaces
CodeIgniter is written with the latest PHP version hence allows the use of Namespace while codeigniter 3 doesn't allow the use of Namespace.
4- Autoloading
CodeIgniter 4 has a powerful autoload process, and one of the most helping factors is Namespace.
5- Use of Entities
Use of Entities is a native support of codeigniter 4, that helps in processing the database part in application, representing the present columns within the tables. while codeigniter 3 doesn't have this feature. So if anyone wants this feature they have to add the third party library and make modifications to file for the support.
6 - Performance
CodeIgniter four requires php 7, server requirement, and in terms of other aspects it is far better than codeigniter three.
7- Monolithic Libraries
use of monolithic libraries in the PEAR style is almost zero in codeigniter 4 while it was in codeigniter 3.
8 - Configurations / Settings
Initial setup for codeigniter four application is very minimal, while it was necessary to perform a number of configurations in codeigniter three.
9 - Native support for .env files
CodeIgniter 4 has inbuilt support of .env like Laravel framework which optimize the settings of different modes like production, development, test while running. This feature doesn't exist in Codeigniter 3.
10 - Migration between versions
CodeIgniter four is not backward compatible, So while updating the application from version 3 to version it needs a bit more work but not complicated at all.
During the migration of version 2.X.X to 3.X.X and between various versions of Codeigniter 3.X.X was just overwriting files in the system folder and renaming a few files. while from codeigniter 3 to codeigniter 4 new structure is required and redevelopment to match the standards.