$_POST is superglobal.
Look at this code and run it. Type something into the box and watch it echo the same text you typed in.
Notice that $_POST['bar'] is still "alive" and available to the class as a superglobal. You shouldn't have to extract into another array to make a copy. Just reference the array in your code (and always check with isset).
<?php
class Foo {
function DoIt() {
echo "You entered:<br />";
echo $_POST['bar']; // best to check with isset
}
}
if (isset($_POST['submit'])) {
$foo = new Foo();
$foo->DoIt();
}
else {
$scriptname = $_SERVER['PHP_SELF'];
$strForm = "<form name='frmFoo' method='post' action='" . $scriptname . "'";
$strForm .= "<input name='bar' size='10' maxlength='10' value='enter'></input>";
$strForm .= "<input type='submit' value='Submit' name='submit'></input>";
$strForm .= "</form>";
echo $strForm;
}
?>
Note that this is the basic structure of a form handler file. The $_SERVER['PHP_SELF'] set for the action attribute of the form sends processing back to this php script.
The following tests for the existence of the submit variable in the POST. If it is set then we know we are to handle the form processing (and not put up the form again).
if (isset($_POST['submit'])) {
Since we now know we want to process the form, just call the form's associated constructor and it's handler - DoIt:
$foo = new Foo();
$foo->DoIt();
Hope this helps.