Fatal error: Cannot redeclare...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Just Another Victim of the Ambient Morality

    Fatal error: Cannot redeclare...

    I have a peculiar bug in my PHP code. It looks something like this:

    Fatal error: Cannot redeclare func_name() (previously declared in
    script.php:57) in script.php on line 57

    I've done a search and determined that "func_name" really is unique.
    Besides, how is this even possible? It was previously declared on the
    same line it's declared?
    Any help is appreciated. Thank you!



  • Tim McGurk

    #2
    Re: Fatal error: Cannot redeclare...

    Are you accidentally including the same file more than once?

    "Just Another Victim of the Ambient Morality" <ihatespam@hotm ail.comwrote
    in message news:Pzchk.2846 67$Ev5.183435@f e09.news.easyne ws.com...
    I have a peculiar bug in my PHP code. It looks something like this:
    >
    Fatal error: Cannot redeclare func_name() (previously declared in
    script.php:57) in script.php on line 57
    >
    I've done a search and determined that "func_name" really is unique.
    Besides, how is this even possible? It was previously declared on the
    same line it's declared?
    Any help is appreciated. Thank you!
    >
    >
    >

    Comment

    • Just Another Victim of the Ambient Morality

      #3
      Re: Fatal error: Cannot redeclare...


      "Tim McGurk" <timmcgurk@yaho o.comwrote in message
      news:O56dnRLSG5 QS-xjVnZ2dnUVZ_ged nZ2d@giganews.c om...
      Are you accidentally including the same file more than once?
      >
      "Just Another Victim of the Ambient Morality" <ihatespam@hotm ail.com>
      wrote in message news:Pzchk.2846 67$Ev5.183435@f e09.news.easyne ws.com...
      > I have a peculiar bug in my PHP code. It looks something like this:
      >>
      >Fatal error: Cannot redeclare func_name() (previously declared in
      >script.php:5 7) in script.php on line 57
      >>
      > I've done a search and determined that "func_name" really is unique.
      > Besides, how is this even possible? It was previously declared on the
      >same line it's declared?
      > Any help is appreciated. Thank you!
      Thank you for the quick reply!
      I don't think I'm including it more than once.
      Actually, what I'm doing is this:

      function func($input)
      {
      function func_name($e)
      {
      return $e + 1;
      }

      return array_map('func _name', $input);
      }

      This appears to be what's causing the error.
      I would have guessed that it was okay but, apparently, defining
      "func_name" in "func" decorates it, somehow. However, I read some
      documentation saying that all function names have global scope, regardless
      of where it was defined.
      So, is this possibly a bug?
      Thank you...


      Comment

      • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

        #4
        Re: Fatal error: Cannot redeclare...

        Just Another Victim of the Ambient Morality escribió:
        function func($input)
        {
        function func_name($e)
        {
        return $e + 1;
        }
        >
        return array_map('func _name', $input);
        }
        func_name() is declared when you run func(). That means that if you run
        func() more than once you'll declare func_name() more than once, what is
        not allowed.

        Just move func_name() outside func(), I see no reason to declare it inside.

        It looks like you've done lots of JavaScript stuff. Sorry, PHP is way
        different.

        So, is this possibly a bug?
        Yes, it's a bug in your code ;-)



        --
        -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
        -- Mi sitio sobre programación web: http://bits.demogracia.com
        -- Mi web de humor al baño María: http://www.demogracia.com
        --

        Comment

        • vetter.a@googlemail.com

          #5
          Re: Fatal error: Cannot redeclare...

          On Jul 22, 7:05 am, "Just Another Victim of the Ambient Morality"
          <ihates...@hotm ail.comwrote:
          "Tim McGurk" <timmcg...@yaho o.comwrote in message
          >
          news:O56dnRLSG5 QS-xjVnZ2dnUVZ_ged nZ2d@giganews.c om...
          >
          Are you accidentally including the same file more than once?
          >
          "Just Another Victim of the Ambient Morality" <ihates...@hotm ail.com>
          wrote in messagenews:Pzc hk.284667$Ev5.1 83435@fe09.news .easynews.com.. .
             I have a peculiar bug in my PHP code.  It looks something like this:
          >
          Fatal error: Cannot redeclare func_name() (previously declared in
          script.php:57) in script.php on line 57
          >
             I've done a search and determined that "func_name" really is unique.
             Besides, how is this even possible?  It was previously declared on the
          same line it's declared?
             Any help is appreciated.  Thank you!
          >
              Thank you for the quick reply!
              I don't think I'm including it more than once.
              Actually, what I'm doing is this:
          >
          function func($input)
          {
              function func_name($e)
              {
                  return $e + 1;
              }
          >
              return array_map('func _name', $input);
          >
          }
          >
              This appears to be what's causing the error.
              I would have guessed that it was okay but, apparently, defining
          "func_name" in "func" decorates it, somehow.  However, I read some
          documentation saying that all function names have global scope, regardless
          of where it was defined.
              So, is this possibly a bug?
              Thank you...
          function func($input) {
          if (!function_exis ts('func_name') ) {
          function func_name($e){{
          return $e + 1;
          }
          }
          return array_map('func _name', $input);
          }

          Try this!

          greetz Alex

          Comment

          • vetter.a@googlemail.com

            #6
            Re: Fatal error: Cannot redeclare...

            On Jul 22, 7:10 pm, "vette...@googl email.com"
            <vette...@googl email.comwrote:
            On Jul 22, 7:05 am, "Just Another Victim of the Ambient Morality"
            >
            >
            >
            <ihates...@hotm ail.comwrote:
            "Tim McGurk" <timmcg...@yaho o.comwrote in message
            >
            news:O56dnRLSG5 QS-xjVnZ2dnUVZ_ged nZ2d@giganews.c om...
            >
            Are you accidentally including the same file more than once?
            >
            "Just Another Victim of the Ambient Morality" <ihates...@hotm ail.com>
            wrote in messagenews:Pzc hk.284667$Ev5.1 83435@fe09.news .easynews.com.. ..
            >   I have a peculiar bug in my PHP code.  It looks something like this:
            >
            >Fatal error: Cannot redeclare func_name() (previously declared in
            >script.php:5 7) in script.php on line 57
            >
            >   I've done a search and determined that "func_name" really is unique.
            >   Besides, how is this even possible?  It was previously declared on the
            >same line it's declared?
            >   Any help is appreciated.  Thank you!
            >
                Thank you for the quick reply!
                I don't think I'm including it more than once.
                Actually, what I'm doing is this:
            >
            function func($input)
            {
                function func_name($e)
                {
                    return $e + 1;
                }
            >
                return array_map('func _name', $input);
            >
            }
            >
                This appears to be what's causing the error.
                I would have guessed that it was okay but, apparently, defining
            "func_name" in "func" decorates it, somehow.  However, I read some
            documentation saying that all function names have global scope, regardless
            of where it was defined.
                So, is this possibly a bug?
                Thank you...
            >
            function func($input) {
                if (!function_exis ts('func_name') ) {
                            function func_name($e){{
                                    return $e + 1;
                            }
                    }
                return array_map('func _name', $input);
            >
            }
            >
            Try this!
            >
            greetz Alex
            function func($input) {
            if (!function_exis ts('func_name') ) {
            function func_name($e) { // without double curly brackets
            return $e + 1;
            }
            }
            return array_map('func _name', $input);
            }

            Comment

            Working...