Conditionally define a function in php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Quinten Carlson

    Conditionally define a function in php

    Is there a way to conditionally define a function in php?

    I'm trying to run a php page 10 times using the include statement, but I get
    an error because my function is already defined. The docs state that a
    function cannot be undefined and adding "exit" to the included page doesn't
    free it up either.

    Any suggestions?

    B44CCD21


  • CC Zona

    #2
    Re: Conditionally define a function in php

    In article <9i1Qa.44068$OZ 2.8100@rwcrnsc5 4>, "Quinten Carlson" <no@no.com>
    wrote:
    [color=blue]
    > Is there a way to conditionally define a function in php?
    >
    > I'm trying to run a php page 10 times using the include statement, but I get
    > an error because my function is already defined.[/color]



    --
    CC

    Comment

    • sam

      #3
      Re: Conditionally define a function in php

      if(!function_ex ists("my_functi on"))
      {
      //define your fumction my_function here
      }
      else
      {
      // do other stuff here
      }


      "Quinten Carlson" <no@no.com> wrote in message
      news:9i1Qa.4406 8$OZ2.8100@rwcr nsc54...[color=blue]
      > Is there a way to conditionally define a function in php?
      >
      > I'm trying to run a php page 10 times using the include statement, but I[/color]
      get[color=blue]
      > an error because my function is already defined. The docs state that a
      > function cannot be undefined and adding "exit" to the included page[/color]
      doesn't[color=blue]
      > free it up either.
      >
      > Any suggestions?
      >
      > B44CCD21
      >
      >[/color]


      Comment

      • Quinten Carlson

        #4
        Re: Conditionally define a function in php

        Thanks CC, I dropped the function into an include and require_once'd it.
        Works like a charm!

        B44CCD21
        [color=blue]
        > http://php.net/require-once
        >
        > --
        > CC[/color]


        Comment

        Working...