note 32038 deleted from function.eval by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 20:01:34 +0000 |
| Subject: | note 32038 deleted from function.eval by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155310@lists.php.net to get a copy of this message | ||
Note Submitter: G Systemacher
----
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.