开发者

How many max constants can i define in PHP?

开发者 https://www.devze.com 2023-01-02 16:46 出处:网络
My site is having around 100+ constants defined and this can potentially reach 200. I\'m using define() for defining constan开发者_如何转开发t.

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

I'm using define() for defining constan开发者_如何转开发t.

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


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消