2008年5月19日 星期一

Class , Array , Composite Implement and Practice

1 . class attribute => array
=>$this->a['a'];

class c
{
var $a = array('a'=>'aa','b'=>'ab');
var $b = 'c';

function show()
{
echo $this->a['a']; // -> 1st
echo $this->a['b']; // outputs 'ab'

$a = 'a';
$b = 'b';

echo $this->$a[$a]; // [] 1st, not what I expected
//Above first becomes $this->$a['a'] by looking at the function's local $a
//Next it becomes $this->a by again looking at the function's local $a, which references the class variable $a with no subscripts.
// In order to reference elements of the class variable $a,
// you want to use $this->a[$a]

echo $this->$a[$b]; // does NOT output 'ab'
// Same as above, but the first step $b becomes 'b'

$this_a =& $this->$a; // work-around

echo $this_a[$a]; // no question
echo $this_a[$b];

$a_arr = array('a'=>'b');

echo $this->$a_arr[$a]; // [] 1st => outputs 'c'
// This becomes $this->$a_arr['a'] which becomes $this->c,
// by referencing the local variables first.
}
}
$c = new c();
$c->show();
?>
2. array 0=>object
class test{
var $go =5;
var $go1 =15;
var $go2 =25;
}

class test2{
var $go =5;
var $go1 =15;
var $go2 =25;
}
$array = Array(new test,new test2);
Array ( [0] => test Object ( [go] => 5 [go1] => 15 [go2] => 25 ) [1] => test2 Object ( [go] => 5 [go1] => 15 [go2] => 25 ) )

關於我自己

Aspire freedom , Hope to do Soming make self complete ~