Jump to content

Pimple container -vs- defined constant for SITEPATH etc...


Firemankurt

Recommended Posts

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?

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.

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.