Background: Suppose I have the following obviously-incorrect PHP:
try{
$vtest = '';
print(array_pop($vtest));
}catch(Exception $exx){}
For it to work with array_pop, $vtest should obviously be an array, not a string. Nevertheless, when I run this code the Warning is exhibited. I don't want that, I just want the code to fail silently.
Question: Is there something special about PHP try-catch compared to other languages that cause this not to work?
Disclaimer:
Just for reference, it is true there are other ways to handle this situation in PHP, but these are undesirable. The goal here is to avoid:
The "at-sign" trick:
$vtest = '';
print(@array_pop($vtest)); // <-- would like to avoid this
Type Casting:
$vtest = '';
$vtest = (array)$vtest;
print(array_pop($vtest));
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…