Firemankurt Posted January 1, 2014 Share Posted January 1, 2014 I am moving my framework to use Pimple Is there any advantage to storing things like SITEPATH or SITE_DOMAIN in Pimple vs in a defined constant? When is one a better choice than the other or is it just personal preference and expected use? Quote Link to comment https://forums.phpfreaks.com/topic/285029-pimple-container-vs-defined-constant-for-sitepath-etc/ Share on other sites More sharing options...
sKunKbad Posted January 3, 2014 Share Posted January 3, 2014 When you define a constant it is global in scope, so keep that in mind. The container is only accessible when you pass it or call it, but constants are available everywhere. Aside from those points, I would just say to do what feels more organized for you application. Quote Link to comment https://forums.phpfreaks.com/topic/285029-pimple-container-vs-defined-constant-for-sitepath-etc/#findComment-1463657 Share on other sites More sharing options...
Solution ignace Posted January 3, 2014 Solution Share Posted January 3, 2014 Though a constant is perfectly fine keep in mind that you don't create any hard dependency between your global constant and any class. class Foo { private $bar = GLOBAL_CONSTANT; }Foo now has a hard dependency on GLOBAL_CONSTANT, pass the constant through the constructor if it needs it's value: $foo = new Foo(GLOBAL_CONSTANT); Quote Link to comment https://forums.phpfreaks.com/topic/285029-pimple-container-vs-defined-constant-for-sitepath-etc/#findComment-1463677 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.