Auto prepend problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lazypig06@gmail.com

    #1

    Auto prepend problem

    Hi !

    I'd like to ask everyone this question. I am currently maintain a
    website which have hundreds of pages and lot of subdirectories. Most of
    these pages contains a common function (let's call it "foo()" on top of
    each of these pages. I've tried to use auto prepend and .htaccess to
    prepend a file which contains an exact function foo() that is being
    used on other pages.

    I kept getting error "Cannot redeclare foo() in..." when I try to use
    ..htaccess and auto prepend feature. I've tried to remove foo() from
    each page and use the foo() in the include file instead, but this
    process take too much time. Is there anyway that I can tell PHP to
    ignore the foo() function that is being redeclare in each page ? (I
    know that I eventually have to remove foo() in every page).

    Sorry for a lengthy question.

    Thank you in advance,
    Lazy Pig

  • m2m tech support

    #2
    Re: Auto prepend problem

    lazypig06@gmail .com wrote:
    ... Is there anyway that I can tell PHP to
    ignore the foo() function that is being redeclare in each page ? (I
    know that I eventually have to remove foo() in every page).
    Sorry, don't know of such a solution. Could you do the following?
    Write a script which browses all your pages and when it finds "foo()"
    just rename it to something like "foo_old()" .

    Cheers

    Comment

    • Tim Hunt

      #3
      Re: Auto prepend problem


      lazypig06@gmail .com wrote:
      Hi !
      >
      I'd like to ask everyone this question. I am currently maintain a
      website which have hundreds of pages and lot of subdirectories. Most of
      these pages contains a common function (let's call it "foo()" on top of
      each of these pages. I've tried to use auto prepend and .htaccess to
      prepend a file which contains an exact function foo() that is being
      used on other pages.
      >
      I kept getting error "Cannot redeclare foo() in..." when I try to use
      .htaccess and auto prepend feature. I've tried to remove foo() from
      each page and use the foo() in the include file instead, but this
      process take too much time. Is there anyway that I can tell PHP to
      ignore the foo() function that is being redeclare in each page ? (I
      know that I eventually have to remove foo() in every page).
      >
      Sorry for a lengthy question.
      >
      Thank you in advance,
      Lazy Pig
      There are at least two ways you could do this: Put the declaration of
      foo() inside this if block, if( !function_exist s('foo')) { .... }, so
      the function is only parsed if it hasnt already been declared. Another
      way is put if( defined('fufile ') ) {return;} define('fufile' ,1); at the
      top of the file foo() is declared in - it quickly exists the include'd
      file when it is included a 2nd/3rd/... time.

      Tim

      Comment

      • lazypig06@gmail.com

        #4
        Re: Auto prepend problem

        Hi !

        Thank you for your response. I already tried the first method, but that
        didn't work since auto prepend happened first, then the foo() function
        in each page is being process next.

        What do you mean "fufile" in your second method ? is it the include
        file's name which contains foo() function ?

        Thank you for your help,
        Lazy Pig


        Tim Hunt wrote:
        lazypig06@gmail .com wrote:
        Hi !

        I'd like to ask everyone this question. I am currently maintain a
        website which have hundreds of pages and lot of subdirectories. Most of
        these pages contains a common function (let's call it "foo()" on top of
        each of these pages. I've tried to use auto prepend and .htaccess to
        prepend a file which contains an exact function foo() that is being
        used on other pages.

        I kept getting error "Cannot redeclare foo() in..." when I try to use
        .htaccess and auto prepend feature. I've tried to remove foo() from
        each page and use the foo() in the include file instead, but this
        process take too much time. Is there anyway that I can tell PHP to
        ignore the foo() function that is being redeclare in each page ? (I
        know that I eventually have to remove foo() in every page).

        Sorry for a lengthy question.

        Thank you in advance,
        Lazy Pig
        >
        There are at least two ways you could do this: Put the declaration of
        foo() inside this if block, if( !function_exist s('foo')) { .... }, so
        the function is only parsed if it hasnt already been declared. Another
        way is put if( defined('fufile ') ) {return;} define('fufile' ,1); at the
        top of the file foo() is declared in - it quickly exists the include'd
        file when it is included a 2nd/3rd/... time.
        >
        Tim

        Comment

        • Tim Hunt

          #5
          Re: Auto prepend problem


          lazypig06@gmail .com wrote:
          Hi !
          >
          Thank you for your response. I already tried the first method, but that
          didn't work since auto prepend happened first, then the foo() function
          in each page is being process next.
          >
          What do you mean "fufile" in your second method ? is it the include
          file's name which contains foo() function ?
          >
          Thank you for your help,
          Lazy Pig
          >
          Hmm sorry it wont work - I misread the problem, thought you were
          including a file on every page and the included file contained foo(),
          having the function foo() defined every page is very different and what
          I suggested won't work.

          fufile was just the name of a constant to record whether a file had
          been included or not, it could have been anything.

          Tim

          Comment

          • Tim Hunt

            #6
            Re: Auto prepend problem


            lazypig06@gmail .com wrote:
            Hi !
            >
            Thank you for your response. I already tried the first method, but that
            didn't work since auto prepend happened first, then the foo() function
            in each page is being process next.
            Try the first method but swap auto_prepend for auto_append..

            Tim

            Comment

            Working...