Welcome Guest, Not a member yet? Register   Sign In
General use class: static or not?
#6

(This post was last modified: 05-07-2020, 03:07 PM by nicojmb.)

(05-07-2020, 08:53 AM)YanKleber Wrote: I see... well I am not sweating too much about this... I tested and both methods work without any noticeable difference. I just was imagining if one of them couldĀ be considered more "correct". Thanks!

Cool

Hi, if is CI4 make your class as service and you call directly like this:

PHP Code:
$class = \Config\Services::yourClass();
$class->yourVariable;
$class->yourMethod();
or
$variable = \Config\Services::yourClass()->yourVariable;
or
$method = \Config\Services::yourClass()->yourMethod(); 

Here are docs:

https://codeigniter4.github.io/userguide...vices.html
Reply


Messages In This Thread
General use class: static or not? - by YanKleber - 05-06-2020, 02:04 PM
RE: General use class: static or not? - by nicojmb - 05-07-2020, 03:05 PM



Theme © iAndrew 2016 - Forum software by © MyBB