Home > other >  Require a PHP file into another
Require a PHP file into another

Time:02-20

I was trying to require a php file into another but it keeps giving me this fatal error: Fatal error: Cannot redeclare sendMessage() (previously declared in /app/functions.php:9) in /app/functions.php on line 9 That's the code I'm using:

require_once "functions.php";
sendMessage($chatid, "Tetx here");
function sendMessage($chatid, $text){
    some code here...
}

CodePudding user response:

As you can see in the error message you cannot declare a function multiple times.

Assume that you have already declared sendMessage() in functions.php like below:

function sendMessage(bla, bla, ...) {
  some code...
}

Then you have redeclared it in functions.php or the main PHP file that you have required functions.php like below:

function sendMessage(...) {
  some code again...
}

You'll be faced with the error message that you have mentioned.

If the situation is like that, you need to delete one of them.

CodePudding user response:

Don't require functions.php into function.php

  • Related