Like this: <?php echo Logic::getFirstValue(); // Output: first value class Logic { public static function getFirstValue() { return Data::getData('firstArray','firstKey'); // without $ } } class Data { private static $firstArray = array ('firstKey'=>'first value'); private static $secondArray = array ('secondKey'=>'second value'); public static function getData($array, $key) { return self::${$array}[$key]; } } ?> Greetings n3or Luigi Perroti schrieb:
Hi all, I'm rewriting a script trying to avoid using functions that might pose a security threat if used incorrectly. I have a portion of code that looks like the one pasted below. I don't seem to be able to avoid using eval without introducing too many changes, losing in simplicity. Here's the code: <?php echo Logic::getFirstValue(); // Output: first value class Logic { public static function getFirstValue() { return Data::getData('$firstArray','firstKey'); } } class Data { private static $firstArray = array ('firstKey'=>'first value'); private static $secondArray = array ('secondKey'=>'second value'); public static function getData($array, $key) { $string = 'return self::'.$array.'[\''.$key.'\'];'; return eval ($string); } } ?> How would you rewrite the snippet without using eval and still keeping things very straightforward? Thanks for your attention!
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php