-1
function createStudentMarks($key)
{    echo "key".$key;exit;    }

This is my function.

$StudentMarks=createStudentMarks($key);

And i have called function in same file like this n im getting fatal error. Y is it so can anyone please help me

Cannot redeclare createStudentMarks() (previously declared in /var/www/html/2016/S/Mcd_BuildStudentsMarks.php:85) in /var/www/html/2016/S/Mcd_BuildStudentsMarks.php on line 85 This is the error wat im getting exactly

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
qwerty
  • 17
  • 3
  • 2
    Well the full error message should give you a few more clues, such as where it is being declared/redeclared – Mark Baker Aug 19 '16 at 10:17
  • The parameter you're passing when you call the function, Is it defined ? Just define it and assign some value. eg: `$key = 100` above your function call – Nischal Kumar BC Aug 19 '16 at 10:21
  • parameter is coming from foreach loop no need of declaration – qwerty Aug 19 '16 at 10:24
  • Function is declared in top n im using it in some foreach loop in further code – qwerty Aug 19 '16 at 10:25
  • Cannot redeclare createStudentMarks() (previously declared in /var/www/html/2016/S/Mcd_BuildStudentsMarks.php:85) in /var/www/html/2016/S/Mcd_BuildStudentsMarks.php on line 85 This is the error wat im getting exactly – qwerty Aug 19 '16 at 10:26
  • Well,The question wasn't sufficient , There are already posts on this , Please refer, http://stackoverflow.com/questions/1953857/getting-a-fatal-error-cannot-redeclare-function-error – Nischal Kumar BC Aug 19 '16 at 10:28
  • Thank you but i already had referred that it is different from wat i want – qwerty Aug 19 '16 at 10:32
  • If the link above does not help you, then how can we. Remember we cannot see what you dont show us and we are not **clairvoyant**. _You must be declaring the function twice (PHP Does not make this stuff up) so now you just have to look for where that might be_ – RiggsFolly Aug 19 '16 at 10:42
  • ok thank you so much for yo time n patience – qwerty Aug 19 '16 at 10:50
  • Are you including this file twice? Or are you doing something crazy like defining the function inside another function? – Mark Baker Aug 19 '16 at 11:36
  • Thank you Mark Baker. Im not including my file twice n there is no other function in whole file other than this – qwerty Aug 19 '16 at 11:39
  • If you are using `include` or `require` replace it with `include_once` or `require_once` – Saurabh Aug 19 '16 at 12:14

1 Answers1

0

Most of the times, this is caused by accidentally requireing or includeing a file more than once.

This generally shows bad coding behavior, so first try to find if this is the case or not. Try to eliminate the second and so on requires or includes.

In any case, you can work around it but using include_once or require_once, which will not include the file on second or next calls.

vfsoraki
  • 2,186
  • 1
  • 20
  • 45
  • Thank you all...my prob is solved...as i have told previously since it was inside foreach loop i was getting that error – qwerty Aug 22 '16 at 06:38