using php classes - scope question & passing variables
Posted: Thu Jan 01, 2009 5:44 pm
I inherited some php code. The program uses global variables to pass around arrays of information. It work, but it seems to not be in the spirit of OO programming. Here is example that illustrates my point. Can someone propose a better way to access variables in class functions, outside the scope of the function?
Code: Select all
<?php
class clRegistration
{
var $gblFormvars ;
function fnShowForm()
{
global $gblFormvars;
$q = "'";
$dq = "\"";
$comma = ", ";
echo "<form method='get' action=" .$q . $_SERVER['PHP_SELF'] . $q . ">";
echo "Name ";
echo " <input type='text' name='registrantName' value=" . $dq . $gblFormvars['registrantName'] . $dq . "\" />";
echo "<br><input type='submit' name='action' value='submit' />";
}
function fnCleanFormData(&$formvars)
{
global $gblFormvars;
$formvars['registrantName'] = empty($formvars['registrantName']) ? "" : $formvars['registrantName'];
$gblFormvars = $formvars;
}
}
$RegistrationObj = new clRegistration;
$RegistrationObj->fnCleanFormData($_REQUEST);
$RegistrationObj->fnShowForm();
?>