How to prevent includes from attempting redefinitions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Tyler

    How to prevent includes from attempting redefinitions

    I import library routines using include(...);

    However, importing library routines that themselves use other library routines
    easily leads to repeated declarations - which give errors of the form:

    ``Fatal error: Cannot redeclare method_name() (previously declared in
    /usr/local/home/httpd/vhtdocs/timtyler/php/table_highlight _border.inc.php :2)
    in /usr/local/home/httpd/vhtdocs/timtyler/php/table_highlight _border.inc.php
    on line 11''

    Should I try setting flags - and doing things conditionally?

    What is the best approach for working around this issue?
    --
    __________
    |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.
  • John Downey

    #2
    Re: How to prevent includes from attempting redefinitions

    Tim Tyler wrote:[color=blue]
    > I import library routines using include(...);
    >
    > However, importing library routines that themselves use other library routines
    > easily leads to repeated declarations - which give errors of the form:
    >
    > ``Fatal error: Cannot redeclare method_name() (previously declared in
    > /usr/local/home/httpd/vhtdocs/timtyler/php/table_highlight _border.inc.php :2)
    > in /usr/local/home/httpd/vhtdocs/timtyler/php/table_highlight _border.inc.php
    > on line 11''
    >
    > Should I try setting flags - and doing things conditionally?
    >
    > What is the best approach for working around this issue?[/color]
    Try include_once() that way PHP will keep track of if it has included
    the file already and won't try again.

    --
    John Downey




    Comment

    • Tim Tyler

      #3
      Re: How to prevent includes from attempting redefinitions

      John Downey <blah@doesntexi st.com> wrote or quoted:[color=blue]
      > Tim Tyler wrote:[/color]
      [color=blue][color=green]
      >> What is the best approach for working around this issue?[/color]
      >
      > Try include_once() that way PHP will keep track of if it has included
      > the file already and won't try again.[/color]

      Thanks.
      --
      __________
      |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.

      Comment

      • Randell D.

        #4
        Re: How to prevent includes from attempting redefinitions


        "Tim Tyler" <tim@tt1lock.or g> wrote in message news:HnB6L0.C9q @bath.ac.uk...[color=blue]
        > I import library routines using include(...);
        >
        > However, importing library routines that themselves use other library[/color]
        routines[color=blue]
        > easily leads to repeated declarations - which give errors of the form:
        >
        > ``Fatal error: Cannot redeclare method_name() (previously declared in
        >[/color]
        /usr/local/home/httpd/vhtdocs/timtyler/php/table_highlight _border.inc.php :2)[color=blue]
        > in[/color]
        /usr/local/home/httpd/vhtdocs/timtyler/php/table_highlight _border.inc.php[color=blue]
        > on line 11''
        >
        > Should I try setting flags - and doing things conditionally?
        >
        > What is the best approach for working around this issue?
        > --
        > __________
        > |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.[/color]

        You can use include_once() or else perform your includes from within the
        parent calling script (as opposed to having one include inside another
        included function/script), place what you want to include at the very
        begining of your script


        Comment

        Working...