Fake Continuations
for PHP

Brock Wilcox

awwaiid@thelackthereof.org

Presentation Outline

Statefullness on the Web

HTTP is stateless, meaning that it isn't an ongoing conversation, but rather a series of one-thought quips sent back and forth. Not a very good way to converse!

Memento

Who has seen Memento? Check it out on IMDB.

Memento

Memento - The Code

// The user will tell us what mode we're in
var $program_mode = $_REQUEST["program_mode"];
switch($program_mode) {
  case "list":
    output_list();
    break;
  case "dialog":
    output_dialog();
    break;
  default:
    output_main();
}

Alternative Memento Statelessness

Run Lola Run

Who has seen Run Lola Run? Check it out on IMDB.

Run Lola Run - Continuations

Run Lola Run - The Code

// Get a line of input from the user
// Keep asking till we get something
function input_prompt($msg) {
  var $result = "";
  while($result == "") {
    $f = display_template("templates/dialog.tpl"
      msg => $msg
    );
    $result = $f["result"] || "";
  }
  return $result;
}

Run Lola Run - The Code (cont.)

$verb  = input_prompt("Give me a past-tense verb.");
$noun1 = input_prompt("Give me a noun.");
$noun2 = input_prompt("Give me another noun.");
display("The $noun1 $verb the $noun2!");

Continuations, Not The Silver Bullet

Where do they come from?
Where do they go?

Fake Continuations, Theory

Fake Continuations, Theory (cont.)

Fake Continuations, Good Side Effects

Fake Continuations, Side Effects

Fake Continuations, Implementation


$obj = new $class;
$obj = new Contize($obj);

Fake Continuations, Implementation

Random References