Supported Versions: PHP 5 >= 5.5.0, PHP 7, PHP 8
Get the boolean value of a variable
<?php boolval(mixed $value): bool
<?php     protected function isUniqueConstraintError(Exception $exception)

    {

        return boolval(preg_match('#Integrity constraint violation: 1062#i', $exception->getMessage()));

    }
<?php     protected function isUniqueConstraintError(Exception $exception)

    {

        return boolval(preg_match('#(column(s)? .* (is|are) not unique|UNIQUE constraint failed: .*)#i', $exception->getMessage()));

    }
<?php     protected function isUniqueConstraintError(Exception $exception)

    {

        return boolval(preg_match('#Cannot insert duplicate key row in object#i', $exception->getMessage()));

    }