CodeIgniter4 - eventually after three years development

I am delighted to say CodeIgniter4 has just been released today after three long years.

No longer just a single Class that called sub-classes this version has all the latest bells and whistles such as NameSpaces

It is still available in a zip file that is only 3.9Mb including the comprehensive documentation!

https://forum.codeigniter.com/thread-75581.html

2 Likes

Have you delved into it much, @John_Betong? I am still using CodeIgniter 3 with all my projects, and was wondering how involved it would be to convert them over to version 4, or if it was even an advantage to do that. I no longer have any clients with apps that I built in CodeIgniter, so we would be talking about all my personal projects that are constantly in development.

Yes and failed in trying to get the CodeIgniter4 developer team to adopt the PHP 7.0 strict mode. The Luddites prefer to pass variables and let PHP do the sloppy type juggling of parameters and return values.

I have created the online demo with a link to the Github source that adds declare(strict_types=1); to every PHP CI4 source /system and /app file.

https://ci4-strict.tk

There are only about four changes required to validate the source and they are shown in the menu.

If the type is not set for the parameters to a method, it does not help turning strict mode on.

I have not browsed the code, but I would assume if they refused to turn strict mode on, it also means the code they made, does not set the parameter types or method return types.

I was surprised to note that the majority of class method all have the type parameters set although I can’t remember seeing the return value set once.

I am a big fan of declaring the strict types because it makes programming s little bit easier.

I think every native PHP function have typed parameters, my favourite is ini_set(‘display_errors’, 1); throws an error! How many online tutorials fail with that error?

Also I think if “type juggling” is eliminated it must reduce processing time and make the applications a little faster.

I could not agree more, we have used it since the ability to use nullable types came in 7.1

The main advantage as I see it is that you catch errors easier, most can even be caught in the IDE while you develop, as it mark it as an error when you pass along wrong type.

Together with utilizing value objects instead of passing along arrays, this makes the old hard to catch bugs caused by an issue in the passed array, type switching errors etc. a thing of the past.

1 Like

I think I am missing out because I do not fully understand the above statement and would be grateful for more information, demo or link to a blog, etc

The use of entities/value objects clearly defines what a method expects to receive, and it also makes it easier to utilize the passed values inside the method.

Example:

public function test(array $user, etc.)

In this case, the array user is supposed to contain 'username, ‘firstname’, ‘lastname’ etc.
However, you do not have any control over if the array actually contain those values when passed to the method.

public function test(string $username, string $firstName, string $lastName, etc.)

A better method could be, something similar to this. However, this can make for a long parameter list for the method.

public function test(Value\User $user)

By passing along an entity of the user, you are certain that it contains the values you need. If it did not the code would have failed earlier. To get the values you would call, $user->getUsername(), $user->getFirstName() etc.

Basically, by utilizing immutable entities (value objects with a state, i.e. user, transaction etc.) and value objects, you significantly cut down on the possible errors that can happen due to wrong information is passed along to methods/classes.

There is a bunch of articles about this, though I recommend you take a look at this talk by Gordon Skinner on domain driven development. He has a straight forward explanation about entities/value objects and why they make sense code wise.

Edit:
Forgot to attach the link.

1 Like

This talk also has a good explanation on value objects: https://www.youtube.com/watch?v=ZJ63ltuwMaE

1 Like

Many thanks for the detailed examples.

I especially like the example of why the arrays are not a good idea. I will endeavour to apply your suggestions in all my new scripts.

I have watched about half of the video and found it hard going and hope to finish watching it once I resolve this current VPS server change - it is not easy :frowning:

Many thanks, I have watched quite a bit of the video and delighted it is good quality and the English easily understood.

I will return once I have completed this current task which is taking quite some time :frowning:

The concept for Hexagonal Architecture is a difficult one, it is a great architecture, but not an easy one to implement in a functional way. I was mainly thinking on the talk for the part on the entity/value objects, at this time, that is what I would recommend you to focus on, and then you can come back to the rest in the talk at a later time when you feel ready.

1 Like

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