note 14200 deleted from language.oop by didou

From: Date: Tue, 03 Jun 2003 22:03:27 +0000
Subject: note 14200 deleted from language.oop by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-49663@lists.php.net to get a copy of this message
Note Submitter: kynaston@yahoo.com ---- Need to turn all post and get variables into properties of a class? Here's how: class Params { function Params() { global $HTTP_POST_VARS, $HTTP_GET_VARS; $params = array_merge($HTTP_POST_VARS, $HTTP_GET_VARS); foreach($params as $k=>$v) { $this->$k = $v; } } } $test = new Params(); foreach(get_object_vars($test) as $k=>$v) { print("$k => $v : "); } 'course, if you've got any class variables with the same name as a get or post variable, you've just clobbered it, but used with care it's handy.

« previous php.notes (#49663) next »