In all the years I have been developing in PHP, I have always heard that using eval()
is evil.
Considering the following code, wouldn't it make sense to use the second (and more elegant) option? If not, why?
// $type is the result of an SQL statement, e.g.
// SHOW COLUMNS FROM a_table LIKE 'a_column';
// hence you can be pretty sure about the consistency
// of your string.
$type = "enum('a','b','c')";
// option one
$type_1 = preg_replace('#^enum\s*\(\s*\'|\'\s*\)\s*$#', '', $type);
$result = preg_split('#\'\s*,\s*\'#', $type_1);
// option two
eval('$result = '.preg_replace('#^enum#','array', $type).';');