Re: Object-oriented $_REQUEST?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



<?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 "" <ebgssth@xxxxxxxxx> schrieb im Newsbeitrag 
news:a23effaf0704281156w45680015o7d153265411a3667@xxxxxxxxxxxxxxxxx
> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux