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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…