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"
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?
require_once
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); } } }
@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.
getcontactactiveemails
Reflection
:
if(function_exists('getContactActiveEmails')){ $myfunc = new ReflectionFunction('getContactActiveEmails'); echo 'Function is declared in '.$myfunc->getFileName(). ' starting from line '.$myfunc->getStartLine(). ' to '.$myfunc->getEndLine(); die; }
. 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), .
- ?
This error occurs if your function is defined in a loop, because you are trying to define it at each iteration.