zeeshan_haider000 Posted March 19, 2009 Share Posted March 19, 2009 Hi, Is it possible to call a function that is inside another function? something like: function parent(){ function child($param){ $a = $param+.......; return $a; } //child function echo '......'; som more code..... } //Parent function closed. So when the child function is called, only the value $a is returned without executing the parent function.... Like: $b = child(); echo $b; //$a is echoed Is this possible, if yes, how do you do it? Zee Link to comment https://forums.phpfreaks.com/topic/150220-callingreturning-a-function-inside-of-another-function/ Share on other sites More sharing options...
trq Posted March 19, 2009 Share Posted March 19, 2009 child() only exists within parent() so no, its not plausible. Why on earth would you need said functionality? Link to comment https://forums.phpfreaks.com/topic/150220-callingreturning-a-function-inside-of-another-function/#findComment-788905 Share on other sites More sharing options...
zeeshan_haider000 Posted March 19, 2009 Author Share Posted March 19, 2009 child() only exists within parent() so no, its not plausible. Why on earth would you need said functionality? I am trying to create a cache system, and i need the said functionality to check if the contents are changed or not with a query.... Link to comment https://forums.phpfreaks.com/topic/150220-callingreturning-a-function-inside-of-another-function/#findComment-788910 Share on other sites More sharing options...
trq Posted March 19, 2009 Share Posted March 19, 2009 Maybe an object is what your after, I still don't really see what your trying to do. Link to comment https://forums.phpfreaks.com/topic/150220-callingreturning-a-function-inside-of-another-function/#findComment-788911 Share on other sites More sharing options...
zeeshan_haider000 Posted March 19, 2009 Author Share Posted March 19, 2009 Will this work instead? function parent($what){ if ($what = 'child function'){ function child($param){ $a = $param+.......; return(or if return doesnt work, then i guess echo) $a; exit() } //child function else{ parent function } }//parent function closed what i am trying to do is that i have a meta tag with the the number of rows from db as its content, and i am trying to compare it using the above function, by getting the number of rows and compare it with the one in the file.... the child function must inside of the parent function because parent function is important to what i am doing, as it does everything... Link to comment https://forums.phpfreaks.com/topic/150220-callingreturning-a-function-inside-of-another-function/#findComment-788920 Share on other sites More sharing options...
corbin Posted March 19, 2009 Share Posted March 19, 2009 Uh I get your explanation, but I don't get why that involves a child function. Link to comment https://forums.phpfreaks.com/topic/150220-callingreturning-a-function-inside-of-another-function/#findComment-788926 Share on other sites More sharing options...
zeeshan_haider000 Posted March 19, 2009 Author Share Posted March 19, 2009 Uh I get your explanation, but I don't get why that involves a child function. lol i will just modify the parent function then, you are right no need for child function, wanted to make thing simpler for later use but made it more confusing.... EDIT: Dang it, i forgot i can't do that, as there is some code that must be executed after only which the child function/code should be executed.... like parent function{ condition... do this.. if this == condition.. then do this.. and then do child()... hmm Link to comment https://forums.phpfreaks.com/topic/150220-callingreturning-a-function-inside-of-another-function/#findComment-788927 Share on other sites More sharing options...
corbin Posted March 19, 2009 Share Posted March 19, 2009 Doing and defining child are too separate things.... Why not do: function parent() { if(something) { child(); } } function child() { } ??? Link to comment https://forums.phpfreaks.com/topic/150220-callingreturning-a-function-inside-of-another-function/#findComment-788950 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.