开发者

Incurring the resource from another class, the resource table

开发者 https://www.devze.com 2023-03-31 14:47 出处:网络
I am looking for a way to load an array from another class, as in the Kohana Framework. But I fail to get the message Notice: Undefined variable: tab1

I am looking for a way to load an array from another class, as in the Kohana Framework. But I fail to get the message Notice: Undefined variable: 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);


Try this:

public function config($var){

  return $this->$var;

}


 return $this->$var;

is correct. Use it instead of

return $$var;
0

精彩评论

暂无评论...
验证码 换一张
取 消