I don't understand why my machine running PHP 7.2.9 gives this error:
Fatal error: Cannot declare class Error, because the name is already in use in controllers\error.php on line 3
I have a file named controllers/error.php
which contains:
<?php
class Error {
function __construct() {
echo 'Error: 404 not found the file.';
}
}
Meanwhile, I have a file named /index.php
which contains:
require "controllers/error.php";
$controller = new Error;
Even if I change from require
to require_once "controllers/error.php"
, it still keeping reporting the same message.
Error
is a built-in class in PHP 7.
As such, you cannot make a class Error {}
.
Rename the class, or put it in a namespace to avoid conflict.
(Or, as a third option, you could consider using/extending the built-in class instead of making your own error handling system from scratch.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With