4 ms·
What's up with the constant usage of compact()? Isn't it as icky and avoidable as its inverse, explode()? Starting off the 'Technology' tab with supported OSes
by tmcw 16y ago
What's up with the constant usage of compact()? Isn't it as icky and avoidable as its inverse, explode()?
Starting off the 'Technology' tab with supported OSes and servers couldn't be a good idea: those familiar with PHP will understand that incompatible with a system on which PHP is supported is a bug, but compatibility within PHP is obvious.
That said, the event system is interesting, and might be a good rethink of the Drupal hook system.
- mcantelon 16y agoIt's inverse is extract(). What's icky about using compact()?
- photon_off 16y agoWhenever 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.
- mcantelon 16y ago>What makes it icky is that developers then need to worry about how they name their variables. Good point.
- tmcw 16y agoBecause 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?
- mcantelon 16y ago>if I wanted to template each list item in an array, I could use array_map with another template function Good point.
- EGreg 16y agoI think you mean "extract", not "explode". And no, it's not icky. It's a very nice construct by PHP, to avoid having to write: array ('foo' => $foo, 'bar' => $bar, ...) and just write compact('foo', 'bar') what's wrong with that? :) About the event system: Thanks man, I put a lot of effort into it. It's way faster than the drupal system, and also more extensible.