468,135 Members | 1,466 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,135 developers. It's quick & easy.

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
Jul 16 '05 #1
3 4580
In article <9i1Qa.44068$OZ2.8100@rwcrnsc54>, "Quinten Carlson" <no@no.com>
wrote:
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.


http://php.net/require-once

--
CC
Jul 16 '05 #2
sam
if(!function_exists("my_function"))
{
//define your fumction my_function here
}
else
{
// do other stuff here
}
"Quinten Carlson" <no@no.com> wrote in message
news:9i1Qa.44068$OZ2.8100@rwcrnsc54...
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

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

B44CCD21
http://php.net/require-once

--
CC

Jul 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Nevyn Twyll | last post: by
4 posts views Thread by Lord0 | last post: by
2 posts views Thread by Felix | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.