Answer the question
In order to leave comments, you need to log in
How to pass variables to static method?
I need to pass one variable to the method, he has the rest necessary for work in the class, but he does not see them and says Undefined variable about b and c
How best to do in this case? Put them inside the method directly? What if they are needed in another class method?
class MyClass
{
private $b = 1;
private $c = 2;
public static function data($a, $b, $c){
$res = $a + $b + $c;
return $res;
}
}
$res = MyClass::data(25);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question