Is there any way in PHP to call an object like it's a function?
class Funct {
public function __callSelf() {
echo 'Called!';
}
}
$myFunc = new Funct();
$myFunc();
// Output
Called!
Something like this?
Is there any way in PHP to call an object like it's a function?
class Funct {
public function __callSelf() {
echo 'Called!';
}
}
$myFunc = new Funct();
$myFunc();
// Output
Called!
Something like this?
You can try with
__invoke
magic method.Try with
__construct()
or__invoke()
.