从另一个类(资源表)中产生资源


Incurring the resource from another class, the resource table

我正在寻找从另一个类加载数组的方法,如在Kohana框架中。但我没有得到消息通知:未定义变量:tab1

<?php
class A {
    private $tab1 = array('raz'=>true, 'dwa'=>false);
    private $tab2 = array('trzy'=>false, 'cztery'=>true);
    public function config($var) {
        return $$var;
    }
}
class B {
    public function get() {
        $ob = new A;
        $tab = $ob->config('tab1');
        //unset($ob)
        return $tab;
    }
}
$ob=new B;
$tab = $ob->get();
print_r($tab);

试试这个:

public function config($var){
  return $this->$var;
}
 return $this->$var;

是正确的。用它代替

return $$var;