我在一个扩展控制器的homeController类中声明了静态变量。静态变量的值已被方法更改,但是当我尝试访问变量时,它给出null,即更改前的值。是不是假设给出改变的值?
我的代码是这样的:
class HomeController extends Controller{
private static $r_id = null;
public function amethod(){
self::$r_id = 14; //here i have changed the value
}
public function bmethod(){
return self::$r_id; //this result me null while i expect 14
}
}
我哪里出错了,或者我如何在另一种方法中使用一种方法的变量。