472,951 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 software developers and data experts.

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 4859
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: SueB | last post by:
I currently have a 'mail-merge' process in my Access db project. It generates custom filled out Award Certificates based on an SQL SELECT statement in a VBA routine invoked by clicking on a...
3
by: Nevyn Twyll | last post by:
I have a bunch of test case classes (.cs) files in my executable. For security and bloat reasons, I don't want them to compile into a Release executable - only into a Debug build. How do I...
6
by: Arthur | last post by:
I had two Visual Studio .NET C++ solutions that I combined into one. These project solutions were very similar. In fact, the two solutions were sharing many files. Now that they are one...
6
by: Teddy.Gammell | last post by:
Hi, I would like to write a function which does this: for each element in the list call f1() of each element. if f1() return false, break the loop else continue I try to use the...
4
by: Lord0 | last post by:
Hi there, Would like to conditionally validate XML i.e. If element <ElementAhas a particular value then element <ElementBmust have a particular value I'm pretty sure I can't do this this...
2
by: Felix | last post by:
Hello, I use a #define like WITH_MYSTUFF to conditionally compile code within #ifdef WITH_MYSTUFF. I would now like the same define to conditionally link with a library. In the linker settings...
10
by: JurgenvonOerthel | last post by:
Consider the classes Base, Derived1 and Derived2. Both Derived1 and Derived2 derive publicly from Base. Given a 'const Base &input' I want to initialize a 'const Derived1 &output'. If the...
1
by: kaens | last post by:
So, I have a class that has to retrieve some data from either xml or an sql database. This isn't a problem, but I was thinking "hey, it would be cool if I could just not define the functions for...
3
by: yasmin | last post by:
I am trying to conditionally compile macros in my c++ program. I want to simply be able to use the macro name without enclosing it in #ifdef-#endif each time. How can I enclose the macro definition...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.