Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
88 views
in Technique[技术] by (71.8m points)

What is the optimal way of checking constants in PHP?

I have a query regarding the optimal way of checking and comparing constant value in PHP.

for($i=0;$i<500000;$i++){
    if(CHECK_CONSTANT_VALUE =='1'){
        /* nothing */
    }
}



for($i=0;$i<500000;$i++){
   if(defined('CHECK_CONSTANT_VALUE') && CHECK_CONSTANT_VALUE =='1'){
        /* Nothing */
    }
}



for($i=0;$i<500000;$i++){
   if(isset($definers['CHECK_CONSTANT_VALUE']) && $definers['CHECK_CONSTANT_VALUE'] =='1'){
       /* nothing */
   }
}

In option 3 declaring a global variable and assigning all constants to it.

For option 1 and 2 its taking almost same time for execution and same amount of memory is used but for option 3 it takes very less amount of time with same amount of memory.

Can someone please explain this behaviour.?

Thanks,

question from:https://stackoverflow.com/questions/65829377/what-is-the-optimal-way-of-checking-constants-in-php

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...