Call an object like it's a function?

前端 未结 2 515
小蘑菇
小蘑菇 2021-01-21 11:23

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(         


        
2条回答
  •  我在风中等你
    2021-01-21 11:32

    You can try with __invoke magic method.

    The __invoke() method is called when a script tries to call an object as a function.

    Note: This feature is available since PHP 5.3.0.

提交回复
热议问题