clean-code-php
clean-code-php copied to clipboard
Don't write to global functions (classes?)
https://github.com/jupeter/clean-code-php#dont-write-to-global-functions
Could you explain please why you suggest class as a alternative of function in this case? Why classes whouldn't conflict between each other like functions in that example? And why namespaces and naming convenction wouldn't resolve this sort of issue?
I guess such kind of a solution would work fine as well:
use function \App\Helpers\config as myConfig; //just for instance
use function \Path\To\Imported\Package\config;
$app = new Application();
$app->setConfig(myConfig());
$app->setConfig(config());
I think the problem is related to the fact that this section is copied and not very well adapted for PHP.
Of course, the introduction of namespaces is also a solution to the problem.
I would emphasize that Configuration
class should be used as Dependency Injection, and config()
function, even in namespace, is global and can be used anywhere in the program as a global variable.