note 59158 added to function.eval

From: Date: Sun, 27 Nov 2005 22:51:21 +0000
Subject: note 59158 added to function.eval
Groups: php.notes 
Request: Send a blank email to php-notes+get-99213@lists.php.net to get a copy of this message
I'm sure others that don't hold Computer Science degrees have wondered what the whole "recursive" function thing is and why its useful. I won't go into great detail, but imagine if you are storing information and want to tell how to format the values with some sort of extensible templating system. NOTE: This will open up your system to all kinds of attacks, use at your own risk! <?php $dump = "test "; // original string function doThis($i) { // function that we will call recursively echo $i+123; } $function = "doThis"; // which function to call // sample data $data[] = 1; $data[] = 34; $data[] = 30; // imagine this being called in a template function foreach ($data as $value) { // loop through data ob_start(); eval($function."('".$value."');"); // recreate "function" $dump .= ob_get_contents()."\n"; // catch output ob_end_clean(); } echo $dump; /* Outputs: test 124 157 153 */ ?> ---- Manual Page -- http://www.php.net/manual/en/function.eval.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+59158 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59158&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59158&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59158&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59158&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59158&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59158&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59158&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+59158&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#99213) next »