OOP PHP:在创建它们的实例后调用 类 作为函数

OOP PHP: Calling classes as functions after creating an instance of them

创建 class 的实例后我想做的是能够将该实例的名称作为函数调用。例如,考虑以下 class Foo:

$bar = new Foo(5); // generates 5 random ints between 0-100
bar(3); // get the third int in the object bar

这在 PHP 中甚至可能吗?还是会扰乱解析器?提前致谢!

这个问题的真正目的是创建一个 PHP 仿函数,这是我从 here:

中提取的一个例子
<?php

class SquareCallback
{
    public function __invoke($value)
    {
        return $value * $value;
    }
}

$squareObject = new SquareCallback;
var_dump($squareObject(3));