将匿名类设置为函数的参数

问题描述

我正在用PHPStorm在PHP中为Mongodb编写一个小型ODM。在汇总查询中:

$value = $this->creditRepo->execute(AggregateQueryBuilder::create()->project('name','ts')->take(10)->toQuery(),new class{
   public ?string $name;
});

第二个参数是一个匿名类。在execute()函数内部:

function execute(AggregateQuery $query,$class): ArrayObject
    {
        $result = $this->_collection->aggregate($query->getPipeline(),$query->getoptions());
        $returnArray = new ArrayObject();
        foreach ($result as $item){
            $itemx = App::jsonMapper()->map($item,new $class); // $itemx is instance of $class
            $returnArray->append($itemx);
        }

        return $returnArray;
    }

调用者脚本中的结果:

 $value = $this->creditRepo->execute(AggregateQueryBuilder::create()
            ->project('name',new class{
            public ?string $name;
        });
$d = $value->getArraycopy();
$d[0]-> // not type hint,I want it hint to me the <name>

PHPStorm是否可以知道我可以键入的execute()输出提示输出

[编辑] 我尝试使用功能array_map

 $value = $this->creditRepo->execute(AggregateQueryBuilder::create()
    ->project('name','ts')->take(10)->toQuery());
$temp = new class{
   public ?string $name;
};
$output = array_map(static function ($item) use ($temp) {
    $temp->name = $item['name'];
    return $temp;
},(array)$value);
$output[0]->name // type hinted

我想编写一个PHPStorm知道返回的函数,例如array_map怎么做?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...