Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't write to global functions (classes?) #149

Open
andreyvolosyuk opened this issue May 14, 2018 · 1 comment
Open

Don't write to global functions (classes?) #149

andreyvolosyuk opened this issue May 14, 2018 · 1 comment

Comments

@andreyvolosyuk
Copy link

andreyvolosyuk commented May 14, 2018

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());
@andreyvolosyuk andreyvolosyuk changed the title Don't write to global functions (classes without namespaces???) Don't write to global functions (classes without namespaces?) May 14, 2018
@andreyvolosyuk andreyvolosyuk changed the title Don't write to global functions (classes without namespaces?) Don't write to global functions (classes?) May 14, 2018
@peter-gribanov
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants