On Mon, 13 Sep 2004 19:06:20 +0300, Mario Lopez <[EMAIL PROTECTED]> wrote:
> Oh Thanks,
> I thought that only those variables that are defined with VAR
> will be accessible and trieted as class variables
Nope, it'll work:
#!/usr/bin/php
<?php
function bindArray($array, &$obj){
is_array($array) or die("bindArray failed: array expected");
foreach($array as $k => $v){
$obj->$k = $array[$k];
}
}
class Obj {
var $x = 1;
function Obj(){}
}
$o = new Obj();
$a = array(1, 2, 3);
bindArray($a, $o);
print_r($o);
?>
Produces:
obj Object
(
[x] => 1
[0] => 1
[1] => 2
[2] => 3
)
You may want to prefix your key names with some text however. :)
--
Greg Donald
http://destiney.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php