Fatal error: Cannot redeclare password_hash()

You will get this fatal error due to various reasons, let us see all main reasons to solve this issue.

Fatal error: Cannot redeclare password_hash()

1. From PHP 5.5 version and above, password_hash() function included with default php functions, either you need to uncomment / remove your password_hash function and starting using default one that comes php library functions.

2. Or to support PHP all versions, you can check function_exists for password_hash() function to avoid redeclare when it is already declared. Like below example

if (!function_exists('password_hash')) {
function password_hash ($password, $salt) {
// your existing code here .....

By checking function_exists for password_hash function will avoid redeclare fatal error.

3. Or you might declared password_hash function in functions.php (example), while including this php file you might have used include or require, but you need to change this to include_once or require_once

include 'functions.php';
require 'functions.php';

will be changed to

include_once 'functions.php';
require_once 'functions.php';

using include_once or require_once will avoid reusing same script or functions multiple times, this will solve redeclare issues.

Leave a Reply

Your email address will not be published. Required fields are marked *