In PHP, you can "call" an object like a function. The class just needs to implement the __invoke
magic method:
<?php
class MyVeryConfusedClass {
public function __invoke($param1) {
echo "Hello $param1!";
}
}
$whatever = new MyVeryConfusedClass();
$whatever('person'); // greets you
class MyVeryConfusedClass {
public function __invoke($param1) {
echo "Hello $param1!";
}
}
$whatever = new MyVeryConfusedClass();
$whatever('person'); // greets you
Final thoughts
Just ..
why.
Also, how am I just hearing about this after a full 20 years of actively working with PHP? And apparently this has been available since version 5.3? Who is actually using this?