Laravel makes it possible to call a class method using the scope resolution operator (::) without the method being statically declared.
In PHP you can only call static methods only when they are declared as such, for example:
class User {
public static function getAge() { ... }
}
Can be called as User::getAge();
How can this be done in a normal PHP class. I guess for it to be possible it needs to be done using a design pattern or something else. Can anyone help me out?
So what I meant by the above was is it possible to instantiate a class and call it's method statically in php. Since that feature was dropped from previous versions
class Student {
public function examScore($mark_one, $mark_two) {
//some code here
}
}
How do access it in this manner
$student = new Student;
$student::examScore(20, 40);
And I talked about Laravel because it allows you to alias your classes and call it in this manner Student::examScore(20,40);
Something called facade pattern or so. An explanation with example can help.
After a long search I found an article that kind of explains it here:
https://www.sitepoint.com/how-laravel-facades-work-and-how-to-use-them-elsewhere