Unable to update function

function getContactActiveEmails($eid)
{
    global  $db;

    if ($eid) {
        $sql = "SELECT email FROM activeEmails WHERE id = $eid";
        return $db->GetCol($sql);
    }
}

I get the error message "Can not redeclare function getContactActiveEmails"

The line number it gives is the last line of the function - the}

All files are called using require_once. This is the only place in the entire code base where it getContactActiveEmailsis defined. Why is this?

+1
source share
4 answers

With the error, it is very clear that your function is defined twice, so you get an error.

I would recommend you check if a function is defined before declaring it.

if (!function_exists('getContactActiveEmails'))
{
   function getContactActiveEmails($eid)
   {
      global  $db;

     if ($eid) {
         $sql = "SELECT email FROM activeEmails WHERE id = $eid";
         return $db->GetCol($sql);
     }
   }
}
+6
source

@Shakti Singh's solution will work, but keep in mind that you are losing control of your code - you don’t know where this function is declared and what it returns, so I suggest looking for it.

  • , IDE , ​​ getcontactactiveemails -.
  • php, - , Reflection extension

:

if(function_exists('getContactActiveEmails')){
    $myfunc = new ReflectionFunction('getContactActiveEmails');
    echo 'Function is declared in '.$myfunc->getFileName().
         ' starting from line '.$myfunc->getStartLine().
         ' to '.$myfunc->getEndLine();
    die;
}

Reflection

+4

. adhoc.inc.php, php . - -

[13-Jul-2013 21:19:22 Australia/Sydney] PHP Fatal error:  Cannot redeclare checkloggedin() in /Applications/MAMP/htdocs/mycobber/util/adhoc.inc.php on line 4

, , . , , . , , MAMP (apache mysql), .

- ?

0
source

This error occurs if your function is defined in a loop, because you are trying to define it at each iteration.

0
source

All Articles