note 59158 deleted from function.eval by sniper
| From: | sniper@php.net | Date: | Thu, 29 Dec 2005 09:15:51 +0000 |
| Subject: | note 59158 deleted from function.eval by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-100918@lists.php.net to get a copy of this message | ||
Note Submitter: joshuajoe REMOVETHIS [at] gmail
----
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
*/
?>