Forum Moderators: coopster

Message Too Old, No Replies

Can you call one Function inside another function?

Functions inside functions

         

russkern

12:36 pm on Mar 28, 2008 (gmt 0)

10+ Year Member



Or is this where OOP comes into play....

I have a function that sends an email to a user. We'll call it resp_email().

I now have a new function that saves data to a database, but I would like to call the resp_email() function as a response to my different conditions.

R

jatar_k

2:35 pm on Mar 28, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can definitely call one function inside another

have you tried it? did it give you an error or just not work?

russkern

8:30 pm on Mar 28, 2008 (gmt 0)

10+ Year Member



At first it didn't work, but then I noticed a few things which I fixed and now it does.

I really thought it shouldn't have been an issue, but I'm using functions much more lately than I have in the past and I had never tried to call a user-defined function from within another user-defined.

Thanks Jatar_k

jatar_k

9:06 pm on Mar 28, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



glad you got it working

russkern

10:18 am on Mar 29, 2008 (gmt 0)

10+ Year Member



A related question:

I've read threads on this, but they leave me a little confused. If I want to use a variable that has been defined within a function outside of it, what is the best method?

Declairing it a global is what I had intended to do, but reading through a few threads led me to believe that that was not such a good idea and it should be avoided. Am i mis-understanding that?

Is there any other way to do that?

jatar_k

1:24 pm on Mar 29, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could use return [php.net] as well

russkern

3:50 pm on Mar 29, 2008 (gmt 0)

10+ Year Member



OK... thanks... thats what I thought but it didn't seem to work... I'll play around with that though.

Thanks again.