'register_shutdown_function is not working for Doctrine fatal errors
My callback specified in register_shutdown_function is working fine except for the fatal errors of Doctrine.
I'm not using symfony, it's doctine on a simple Php project.
Here is my code
register_shutdown_function(shutdown(...));
function shutdown(): void
{
$err = error_get_last();
if (!is_null($err)) {
handleError(0, $err['message'], $err['file'], $err['line']);
}
}
function handleError(int $severity, string $message, string $filename, int $lineno): ?bool
{
$message = '<pre>' .
'<b>Line #</b>' . $lineno . '<br><br>' .
'<b>File #</b>' . $filename . '<br><br>'
. $message . '<br>' .
'</pre>';
echo $message;
return true;
}
But when it's a Fatal error coming from Doctrine it's not going through my shutdown function.
For example, this code is creating a fatal error because I forgot to add u.before the column name.
class UtilisateurRepository extends EntityRepository
{
public function search($recherche): mixed
{
return $this->_em->createQuery(
"SELECT u FROM App\Entities\Utilisateur u
where
lower(concat(u.nom,' ',u.prenom)) LIKE :recherche
OR lower(concat(prenom,' ',nom)) LIKE :recherche
OR u.email LIKE :recherche
OR u.telephone LIKE :recherche"
)->setParameter('recherche', '%' . strtolower($recherche) . '%')->getResult();
}
}
I think doctrine have it's own shutdown function, but I haven't found any documentation on that, so I'm not sure it even exist, or how to override it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
