Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many max constants can i define in PHP?

Tags:

php

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 ?

like image 264
YD8877 Avatar asked Jun 06 '10 09:06

YD8877


3 Answers

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

like image 51
Sarfraz Avatar answered Sep 28 '22 07:09

Sarfraz


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.

like image 44
cletus Avatar answered Sep 28 '22 08:09

cletus


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

like image 21
StasM Avatar answered Sep 28 '22 07:09

StasM