The variable $maxTry is unassigned when an exception is raised and
the exception handling stops at nTry = 1.
How is this possible?
$nTry=0;
$maxTry=100;
function verify() {
try{
// Some DB Connection
$st = $dbh->prepare(...);
$result = $st->fetchColumn();
}
catch(PDOException $e) {
$nTry++;
echo 'PDOException<br/>';
if($e->getCode()==='HY000') {
echo 'verify again<br/>';
if($nTry < $maxTry) {
$maxTry=100;
verify(); //recursion
}
else
echo "Reached maxTry ($nTry __ $maxTry) PDOException: HY000<br/>";
}
}
verify();
Expected output (if reached maxTry):
PDOException
verify again
...
verify again
Reached max try (100 __ 100) PDOException: HY000
Actual output ($maxTry is not set):
PDOException
verify again
Reached max try (1 __ ) PDOException: HY000