note 32038 modified in function.eval by danbrown
| From: | danbrown@php.net | Date: | Tue, 25 Nov 2008 16:10:56 +0000 |
| Subject: | note 32038 modified in function.eval by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146952@lists.php.net to get a copy of this message | ||
An example of eval within a function within a class sitting on PEAR DB whose purpose is to push onto
a result array named: result_ appended with a parameter key.
<?php
function set_result_array($fn_request_key = '[DEFAULT]', $fn_result) {
$target_array_string = 'result_'.$fn_request_key;
// eval ("global \$\$target_array_string;");
eval("\$target_array =& this->\$target_array_string;");
if (!is_array($target_array)) { $target_array = array(); }
return array_push($target_array, $fn_result);
}
?>
What does this illustrate? An example of using eval to create a reference to an object member by
reference (=&).
The eval ("global ....) line is commented out as I couldn't get this to work for some
reason.
--was--
An example of eval within a function within a class sitting on PEAR DB whose purpose is to push onto
a result array named: result_ appended with a parameter key.
function set_result_array($fn_request_key = '[DEFAULT]', $fn_result) {
$target_array_string = 'result_'.$fn_request_key;
// eval ("global \$\$target_array_string;");
eval("\$target_array =& this->\$target_array_string;");
if (!is_array($target_array)) { $target_array = array(); }
return array_push($target_array, $fn_result);
}
What does this illustrate? An example of using eval to create a reference to an object member by
reference (=&).
The eval ("global ....) line is commented out as I couldn't get this to work for some
reason.
http://php.net/manual/en/function.eval.php