Welcome Guest, Not a member yet? Register   Sign In
Is my library function from common file a good practice ?

(This post was last modified: 06-30-2020, 04:44 PM by ivantcholakov.)

No, it is not.

1. You are making your own unique loading system that somebody else should get used with. Also, this system makes your code less portable.
2. Your function always returns a new instance. Is this always needed? Sometimes singletons are more appropriate.
3. In your sample usage code how do you decide when to use static or dynamic methods? It looks messy.

Edit: You don't need one "good practice", you need a "bag of tricks", a repertoire on how to create objects and on how to access them easily. Object creation depends on the context, and on object's purpose. There are known patterns for these things, get familiar with these concepts when you have the time.

While your project is not too demanding try to stick with what CodeIgniter has got now: https://www.youtube.com/watch?v=iqQufhllUCo

If things get complicated too much and what CodeIgniter proposes is not enough, maybe then you would adopt a more complicated solution that would require more experience. But don't try to invent one. See for example https://php-di.org/ , https://github.com/PHP-DI/PHP-DI

Messages In This Thread
RE: Is my library function from common file a good practice ? - by ivantcholakov - 06-30-2020, 04:13 PM

Theme © iAndrew 2016 - Forum software by © MyBB