What are the advantages and disadvantages of using PHP error reporting for access control compared to .htaccess files?

When it comes to access control in PHP, using PHP error reporting can provide more flexibility and customization compared to using .htaccess files. With PHP error reporting, you can easily handle access control logic within your PHP code, allowing for dynamic access control based on various conditions. However, relying solely on PHP error reporting for access control may introduce potential security risks if not implemented properly.

// Example of using PHP error reporting for access control
if($user_role !== 'admin'){
    header('HTTP/1.0 403 Forbidden');
    echo 'Access Denied';
    exit;
}