DEV Community

Cover image for 10 differences between CodeIgniter 3 and 4
Jonathan Lamim
Jonathan Lamim

Posted on

10 differences between CodeIgniter 3 and 4

Before we talk about the differences, we need to know a little bit about what happened in the time between the release of version 3 and the version.

Between the launch of the first stable version of CodeIgniter 3 and that of CodeIgniter 4, it took almost 5 years, 1767 days to be more precise.

In that time much has changed on the internet, 8 versions of PHP were launched, several other PHP frameworks appeared and those that were already on the market were being updated.

Meanwhile CodeIgniter was lagging behind, going from being one of the main PHP frameworks to becoming one of the most outdated. But all was not lost, EllisLab who was primarily responsible for the development of CodeIgniter passed the baton to BCIT and then thanks to the work of Jim Perry (in memorian) and an incredibly dedicated community, CodeIgniter started to come to life and the version 4 won its first alpha on September 28, 2018.

On February 24, 2020, which would be Jim Perry's birthday, CodeIgniter 4 was launched, in honor of the professional who he devoted a good part of his time in bringing the framework back to the market, with conditions to compete with the other existing frameworks and more updated in relation to resources and PHP itself.

Differences between versions

CodeIgniter 4 is very different from 3 and below you will see a little about the main differences between them.

#1 - Support for PHP versions

To use CodeIgniter 4 the minimum PHP version required is 7.2, while with CodeIgniter 3 it is possible to use from version 5.6 (which has already been completely discontinued).

#2 - Directory organization

The file structure is completely different. CodeIgniter 4 has its structure organized in 5 directories: /app,/system,/public,/writable,/tests. While CodeIgniter 3 is organized in 2 directories:/applicationand/system`.

#3 - Use of namespaces

CodeIgniter 4 is written entirely in PHP 7 and makes use of namespaces, while CodeIgniter 3 does not use namespaces.

#4 - Autoloading

CodeIgniter 4 has a much more efficient autoload process, and one of the factors that help is the use of namespaces. While in CodeIgniter 3 it is necessary to manually configure most of the files to be loaded.

#5 - Use of entities

CodeIgniter 4 has native support for the use of Entities (entities) that help in structuring the database part of an application, representing the existing columns in the tables. CodeIgniter 3 did not have this feature and anyone who needed to use it needed to use third-party libraries and make adjustments to the file upload to support it.

#6 - Performance

CodeIgniter 4, for using PHP 7 in writing and as a minimum configuration on the server, and other aspects, has a better performance than CodeIgniter 3.

#7 - Monolithic Libraries

Unlike CodeIgniter 3, in this new version the use of monolithic libraries in the PEAR style is almost zero.

#8 - Settings

With CodeIgniter 4, the initial settings for your application to start running are minimal, while in CodeIgniter 3 it was necessary to perform a good number of configurations.

#9 - Native support for .env files

CodeIgniter 4 has native support for .env files, allowing an optimization of the settings of the different environments where it may be running (production, tests, development). This feature did not exist natively in CodeIgniter 3.

#10 - Migration between versions

CodeIgniter 4 is not backward compatible, so the process of updating applications from version 3 to version 4 will require a little more work, but it is not at all complicated.

While the migration from version 2.x to 3.x, and between the different versions 3.x was just overwriting the files in the /system directory and updating the name of some files, from version 3 to four a new structure is needed for the application and a rewrite of all the classes used in it to adapt to the new standard.

These are some of the main differences between versions 3 and 4 of CodeIgniter. Stay tuned here that has a lot of content about CodeIgniter 4 being produced.

Top comments (11)

Collapse
 
blair2004 profile image
Blair Jersyer

I likes this framework a lot ne cause it was simple and effective when I was starting php. Then I learned new stuff and I wanted more tools Ci3 couldn't offer.. I've found laravel... And I'm not going back. I'm however wishing them a good luck with the version 4

Collapse
 
prahladyeri profile image
Prahlad Yeri

Nice write up on the new features of CI4!

Having said that, most of them aren't really applicable in context of small PHP shops or freelance programmers like me. For example, I hardly ever use namespaces in PHP as classes suffice for most of the work.

And I also don't have a habit of using a huge list of composer dependency packages. For the rare ones that I do, I've configured autoloading for them and use those projects as baselines for future ones.

Entities are a nice feature but existing database models in C3 do the job too. Me personally, I don't even bother with models but prefer to deal with sql queries directly using $this->db->query($sql). It's a lighter and faster approach with much less clutter!

Performance aspect is interesting but performance will largely depend on the PHP version which is used, not the CI version. If I'm using PHP 7.2+ already, it shouldn't matter whether I use CI 3 or 4 as both should give the same performance.

As regards the large number of config files in CI3, the simple approach here is to create a one-time baseline project with your config preferences, and then start all other projects from there. This method has served me well over the years and I've never had to look back.

Collapse
 
cdsaenz profile image
Charly S.

Great article, still relevant. I've used CI3 for many, many years. And watching CI4 from a distance, testing it now and then. Also Laravel. It took me the time for me to grow into Namespaces and modern PHP in general (which I started using in CI3). One thing to mention in favour of CI4 is advanced inheritance (Base Controllers and Models). I did a lot of that in CI3 and had to do some awful tweaking. In CI4 it's natural PHP, Namespace/use, a simple class in Libraries. I won't migrate my CI3 stuff which works fine (and tightly secured once moved all the code out of www root) but now I'm ready to start new projects with CI4. It also resembles the awesome Laravel: CI4 is like a lightweight/less opinionated Laravel. All are valid choices.

Collapse
 
gabrieldevops profile image
gabo

CodeIgniter 4 Fantastic!!! wit PHP 7 and with PHP 8 JIT , poooowered

Collapse
 
mumingazi profile image
Mumin Gazi

Nice work!

Collapse
 
gunnrcrakr profile image
gunnrcrakr

When CI 4 will release offial ?

Collapse
 
jonathanlamim profile image
Jonathan Lamim

The official release was released on February 24th.

dev.to/jonathanlamim/codeigniter-4...

Collapse
 
benayapaul profile image
Benaya Paul

Good Article was more informative between CI 3 vs CI 4.
Thanks

Collapse
 
faisal95bd profile image
Faisal-95

good article!

Collapse
 
miguelgomezsa profile image
Miguel Gómez

Hi Jonathan, I disagree with you in 8#. CI 3 have a little initial configuration. The same like CI 4.
In the rest of points I am fully agree.
Regards

Collapse
 
jonathanlamim profile image
Jonathan Lamim

Thank you for your feedback Miguel! Is there any other difference that was not mentioned here and that you have already encountered it?