Welcome Guest, Not a member yet? Register   Sign In
Property type hints in Codeigniter 4 (or just PHP 7.4 as a requirement)
#1
Question 
(This post was last modified: 01-17-2020, 06:31 PM by JNapolitanoIT.)

Hey there all, I hope your days are going well.

So, I was combing through the code to help clean up some of the documentation and refactor some of the classes while getting ready to issue a pull request. I have a quick question regarding this, and will await a response before issuing the PR.

Is there any reason why we would not want to use property types in the framework and application classes? For example, the performance increases are extremely beneficial as well as the desired effects. With strongly typed properties, users of the framework will have to adhere to these types.

I was looking in system/Config/BaseConfig.php. Let's use this base example. Say we were to use typed properties, like below:

Instead of:
Code:
/**
* An optional array of classes that will act as Registrars
* for rapidly setting config class properties.
*
* @var array
*/
public static $registrars = [];

We can use this, to make the intentions of the framework's base configuration more clear and throw an error when improperly used.

Code:
/**
* An optional array of classes that will act as Registrars
* for rapidly setting config class properties.
*
* @var array
*/
public static array $registrars = [];

Perhaps a side effect could be that there would be fewer questions on the forums since PHP will do what it does and tell end users where they went wrong in their application? Either way that is a vague example but a proof of concept none-the-less.

Now I realize that this requires PHP 7.4 and the minimum requirement is 7.2 (last I checked). However, I can make the argument that if CodeIgniter is going to utilize PHP 7's capabilities, it should keep up with them. Typed properties being an example. Null coalesce assignment being another or limited return type covariance and argument type contravariance. These features have helped assist in bringing PHP 7.4 into the fastest state the language has been yet. And it also allows for a slightly more opinionated expected use of the framework itself by making clearer some of the intentions of the frameworks developers.

I guess the real question is, can we utilize PHP 7.4 in CodeIgniter going forward? Or are we to stick with the requirement of PHP >= 7.2? Either way, to keep up with the times and technology, we should at least try to utilize some of the features where they can be best taken advantage of.

I hope this makes sense, it has been a long day and I am typing this while extremely tired. Thanks for listening to my rambling Smile
A reader lives a thousand lives before he dies. The man who never reads lives only one.
George R.R. Martin

Reply


Messages In This Thread
Property type hints in Codeigniter 4 (or just PHP 7.4 as a requirement) - by JNapolitanoIT - 01-17-2020, 06:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB