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;
精彩评论