mercredi 10 mai 2017

how to make static variable that can be used in any method of a class in laravel 5.4

I have declare the static varaible in a homeController class that extends controller. The value of static variable has been changed by a method but when i try to access the variable it gives me null that is the value before changed. Is n't it suppose to give the changed value?

my code is like this:

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
}
}

where did i went wrong or how can i use a variable of one method in another.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire