<?php
class get
{
private $array;
function __construct(&$array)
{
$this->array = &$array;
}
public function get($key)
{
if (isset($this->array[$key]))
return $this->array[$key];
return null;
}
}
class request
{
private $types = array('COOKIE', 'REQUEST', 'GET', 'POST', 'SESSION');
function __construct()
{
foreach ($this->types as $type)
{
//do not link the result of eval into a variable because it is passed to
__construct as reference
$this->$type = new get(eval('return $_' . $type . ';'));
}
}
}
$request = new request();
var_dump($request->REQUEST->get('name'));
?>
""js "" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> Hi.
>
> I'm looking for implementation of request object
> that represent a request that works like this.
>
> $r = new request();
> if ($r->method == 'GET')
> $name = $r->GET->get('name');
> $age = $r->GET->get('age');
> else if (request.method == 'POST')
> $name = $r->POST->get('name');
> $age = $r->POST->get('age');
> ...
>
> Handling $_GET, $_POST directly is cumbersome for me
> so I tried to make one but I thought it's quite possible that
> some better programmer already make one like this.
>
> Thanks in advance.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php