6 ms·
Things are even worse in the PHP world than the languages described in the article. You get variable variables and you can use variable as the function/class na
by Arnor 13y ago
Things are even worse in the PHP world than the languages described in the article. You get variable variables and you can use variable as the function/class names so this is totally valid:
function do($class, $action, $param, $value) {
$method = $action.$param
$obj = new $class();
$obj->$method($value);
return $obj
}
$my_name = 'Arnor';
$$my_name = do('Entity', 'set', 'Name', $my_name);
// The entity is now stored in the variable $Arnor
Thanks PHP... Don't even get me started on __call.
It's fun to come up with clever solutions and puzzles, but it harms your code base. If you're proud of how new and clever your last 10 lines were, you probably need to refactor it.