How to avoid the use of session variables in this script [message #180781] |
Mon, 18 March 2013 23:05 |
daveh
Messages: 18 Registered: March 2013
Karma:
|
Junior Member |
|
|
Hello,
I have the following code snippet:
public function register($name, $rule, $dat_file, $server =
DEFAULT_SERVER, $port = DEFAULT_PORT)
{
if(in_array($name, $this->m_names))
{
$this->m_rules[$name][] = $rule;
return $_SESSION[$name];
}
// $cmd = "\$$name = new GTCM_GNP(\$dat_file, \$server, \
$port);";
// eval($cmd);
$$name = new GTCM_GNP($dat_file, $server, $port);
if(!$$name)
{
return FALSE;
}
$this->m_cnt++;
$this->m_names[] = $name;
$this->m_rules[$name] = array($rule);
return $$name;
What exactly does "return $_SESSION[$name]" do? it looks like it just
returns the $name argument in the function list. Or does it save it as
a session variable also? Why not just do: "return $name;" ?? Is there
a better way to do this without using session variables or super
globals? $_SESSION was originally $GLOBALS changing it to $_SESSION
did not break it and it seemed like a better alternative but probably
not the best way. By the way this code was originally written for php
4.0.6 if that makes any difference.
Thanks,
Dave
|
|
|