Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Moderated Pro PHP
|
Moderated Pro PHP This is a moderated forum for discussing advanced, professional level issues with PHP. Your posts will not appear until a moderator approves them. Posts that are not the right level for this forum will be responded to and you'll be asked to post them in the [url="http://p2p.wrox.com/sql-server-2000-20/9"]Beginning PHP[/url] forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Moderated Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2005, 10:51 AM
Authorized User
 
Join Date: Jan 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Functions 'Sumbmitting' back to themselves

I have a page that uses a switch to determine which of a number of functions is called and placed in a div. This gives the effect of that div being multifunctional.

However some of the functions contain forms or other links that require the function to post info back into itself.

Is this possible?

 
Old March 10th, 2005, 06:32 PM
Authorized User
 
Join Date: Dec 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to colin.horne
Default

Please elaberate a bit (I'm unsure what you're wanting).

In the mean time, you may wish to read this: http://uk.php.net/manual/en/function.call-user-func.php

--
Please contact me at:
Colin (dot) Horne (at) gmail (dot) com
My blog: http://colinhorne.blogspot.com
 
Old March 12th, 2005, 09:05 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

I beleive he is talking about calling a function recursively, as in:

function foo()
{
    foo();
}

The above would create an infinite loop, but this is valid. Recursive functions tend to make your head spin. But they work the same as a normal function does, in that, you include a return; statement to pass control back to the calling code. In this case the calling code could be the same function, in which case you control those nested calls with return statements until the whole thing is finished with whatever it is doing. Does that make sense?? Here is an example.

function foo($bar = false)
{
   if ($bar)
   {
       // This value is returned to the recursively called foo
       return 'Hello, world!';
   }
   else
   {
       // A return here will return the value returned by the recursively called foo()
       // Otherwise that returned value would be lost to oblivion.
       return foo(true);
   }
}

echo foo();

The above limits the recursive call on foo to only once, on the second call $bar is true and the value 'Hello, world!' is returned and output.

I've seen some benchmarking that indicates recursive functions can really slow down a script, in my own experience whenever I've needed one however, it hasn't been noticable.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old March 12th, 2005, 09:21 PM
Authorized User
 
Join Date: Dec 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to colin.horne
Default

Hi Richard

> I've seen some benchmarking that indicates recursive functions
> can really slow down a script, in my own experience whenever
> I've needed one however, it hasn't been noticable.

I _think_ this is correct:

When you call up a function, it adds your current memory address to the stack, so once the function has finished, the processor knows where to read the next command from. If you call functions recursively then it can fill up the stack.

Nowerdays we're often spoilt with a huge amount of memory to play around with, but I hear that 'Stack overflow' errors were very common back in the olden days when memory was scarce.

Cheers

--
Please contact me at:
Colin (dot) Horne (at) gmail (dot) com
My blog: http://colinhorne.blogspot.com
 
Old March 14th, 2005, 12:50 PM
Authorized User
 
Join Date: Jan 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry if I wasn't clear what I wanted.

I have an index page that has a switch on it:

Code:
switch ( $transform )
{
  case "test":
      include ("logticket.php");
    logticket();
    break;
  case "test2":
      include ("tableselect.php");
    tableselect();
    break;
  case "test3":
    include ("udateticket.php");
    udateticket($id, $update);
    break;
  case "t_id":
    $query = "SELECT * FROM `ticket` WHERE ticket_status LIKE '$status' ORDER BY ticket_id LIMIT 40";
    include ("tableselect.php");
    tableselect();
    break;
default:
    echo "<div id = content2>";
    echo "This is where the operations that you can perform will appear. You are currently seeing this text because ";
    echo "you have not selected an option yet.";
    echo "</div>";
    break;
}
The functions called in this switch determine what appears in a particular div. Hence this 'box' appears to do many things. One of the functions contains a form and I wanted to reload that function, much like you can submit info back to a page by using $_SERVER['PHP_SELF'] I wondered if it was possible to give a value back to a fuction.

So if foo was to accept $a and $b but it gets the result of $b AFTER being run.

I'm not sure I'm making sense still but I hope I'm making things a little clearer.





Similar Threads
Thread Thread Starter Forum Replies Last Post
C# functions daniel.mihalcea C# 2008 aka C# 3.0 3 September 11th, 2008 05:10 PM
Functions LTello BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 3 September 15th, 2006 11:15 AM
functions xelepi PHP How-To 1 March 10th, 2006 02:59 AM
history.back or hitting the back button won't work lian_a Classic ASP Basics 4 July 29th, 2004 12:14 AM
Help with Functions megabytes C# 1 August 7th, 2003 12:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.