tags:

views:

117

answers:

3

My site is having around 100+ constants defined and this can potentially reach 200.

I'm using define() for defining constant.

Will this cause a performance hit ? How many max constants can i define in PHP ?

+3  A: 

There is no issue with hundreds of constants. I think constants are only limited by memory so you can potentially have many millions if desired.

cletus
*Constants for everyone!* :)
Felix Kling
+5  A: 

PHP uses hundreds of constants itself, so no problem, you can go for as many as u like.

Just put this and see how many constants php uses itself:

$consts = get_defined_constants();
print_r($consts);

Result for me in a page only containing those lines, it showed a total of

990

constants being used with default settings and extensions loaded

Sarfraz
+2  A: 

Basically, you can have as many as memory allows. Hashtable implementation in PHP will ensure they are accessed efficiently. There are limits due to counters being 32-bit or 64-bit integers, but you will run out of memory long before that will become an issue :)

StasM