By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,786 Members | 2,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,786 IT Pros & Developers. It's quick & easy.

Conditionally define a function in php

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.