Re:PHP On Pie takes a fresh new approach.
by mcantelon on Sunday September 12, 2010 @02:28AM
(#1683182)
It's inverse is extract(). What's icky about using compact()?
[ Parent
| on HN ]
Re:PHP On Pie takes a fresh new approach.
by photon_off on Sunday September 12, 2010 @04:28AM
(#1683305)
Whenever reflection can be avoided, it should be. What makes it icky is that developers then need to worry about how they name their variables. It shouldn't be a problem so long there's a convention established.
Personally, when passing a lot of parameters, I condense them into a "Holder" class:
$holder->var1 = "foo";
$holder->var2 = "foo";
//or set from array
$holder->addArray(array("var1"=>"foo", "var2"=>"foo"));
//later on, retrieving values
$holder->useStrictMode(true); //optional: throws exception if key isn't present (rather than returning null)
echo $holder->var1;
echo $holder->var2;
echo $holder->var3; //throws exception that var3 was expected to be present
It's worked well for me. It's also very handy for returning multiple values and status codes.
Re:PHP On Pie takes a fresh new approach.
by mcantelon on Sunday September 12, 2010 @05:26PM
(#1684592)
>What makes it icky is that developers then need to worry about how they name their variables.
Good point.
Because it's highly dependent on scope? Like, if I wanted to template each list item in an array, I could use array_map with another template function, but here I would have to keep re-assigning a variable in a foreach.
And it seems to be unclear on how you'd pass array and object members to it? It seems very much to encourage variable creep?