In all the years I have been developing in php, I've 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')"; // possibility one $type_1 = preg_replace('#^enums*(s*'|'s*)s*$#', '', $type); $result = preg_split('#'s*,s*'#', $type_1); // possibility two eval('$result = '.preg_replace('#^enum#','array', $type).';');