Re: func_get_args as a hash? (faster constructors)

From: Date: Tue, 28 Nov 2006 21:41:05 +0000
Subject: Re: func_get_args as a hash? (faster constructors)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-245242@lists.php.net to get a copy of this message
# kelly.terry.jones@gmail.com / 2006-11-27 18:57:54 -0700: > is there a function I can call inside foo() that yields this hash: > > {"x" => 1, "y" => 2, "z" => "bar"} > > In other words, gives me the values *and names* of the arguments to foo? > > func_get_args just yields the values. > > Having this function would make writing constuctors easier. > > The normal way: > > fuction ClassName ($x, $y, $z) { > $this->x = $x; > $this->y = $y; > $this->z = $z; > } > > could be replaced with: > > function ClassName ($x, $y, $z) { > foreach (magic_function_i_want() as $key=>$val) { > $this->$key =$val; > } > } > > Obviously, it's more of a savings when you have a large number of > parameters. You could use Reflection, but you're probably going down the wrong route with this whole thing. -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991

« previous php.general (#245242) next »