Dynamic variables in PHP from enum
PHP allows computed variable names, but it's nearly always a bad idea.  Unless you are careful about variable naming conventions, you could easily trash a variable accidentally, possibly introducing a security vulnerability.

You would be better off using an associative array.

// Generate dynamic variables testing for equality of
// of $exception and an Enum value from ExceptionModel
foreach ($exceptionModels as $constName =&gt; $constValue) {
    $detected[$constName] = $exception === $constValue;
}

if ($detected['ALLER']) {
    echo "ExceptionModel is aller.";
} else if ($detected['AVOIR_IRR']) {
    echo "ExceptionModel is avoir_irr.";
} else {
    echo "ExceptionModel was neither, it is: " . $exception;
}