note 64337 deleted from language.oop5 by bjori
| From: | bjori@php.net | Date: | Wed, 12 Apr 2006 18:19:52 +0000 |
| Subject: | note 64337 deleted from language.oop5 by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-107909@lists.php.net to get a copy of this message | ||
Note Submitter: mattfoster01 at gmail dot com
Reason: useless
----
Generic classes in php are eeeasy with the eval function
<?php
class my_object{
function set_attribute($my_key, $my_val){
eval('$this ->'.$my_key.' = $my_val;');
}
}#ENDS CLASS
$my_obj = new my_object();
$my_obj -> set_attribute("key", "value");
echo "<pre>".print_r($my_obj, TRUE);
?>
If you found this tip useful and interested in pushing the boundaries of online programming visit my
site at http://www.positionabsolute.net
Good luck!