gpt4 book ai didi

php - Visual Studio Code PHP Intelephense 收到错误

转载 作者:行者123 更新时间:2023-12-03 07:38:42 25 4
gpt4 key购买 nike

我正在使用 Visual Studio Code 和 Intelephense 处理一个 Symfony 4 项目。
Intelephense 得到的错误不是。有一些例子:

Undefined method 'uasort'.


此错误对应于此代码:
// Collection creation of seasons used in the periods 
$seasons = new ArrayCollection();
$sortedSeasons = new ArrayCollection();

//Search seasons used by periods
foreach ($advert->getPeriods() as $period)
{
$season = $period->getSeason();
if (! $seasons->contains($season))
{
$seasons->add($season);
}
}

// Sort seasons by ascending cost
$iterator = $seasons->getIterator();
$iterator->uasort(function ($a, $b) {
return $a->getCost() <=> $b->getCost();
});
另一个例子:

Undefined method 'getAdvertMinPrice'.


$minPrices = $this->getDoctrine()->getRepository(Price::class)->getAdvertMinPrice($advert);
但是,该方法存在于 PriceRepository 中:
<?php
namespace App\Repository\advert;

use App\Entity\advert\Price;
use Symfony\Bridge\Doctrine\RegistryInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;

/**
* @method Price|null find($id, $lockMode = null, $lockVersion = null)
* @method Price|null findOneBy(array $criteria, array $orderBy = null)
* @method Price[] findAll()
* @method Price[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PriceRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Price::class);
}

/**
* Get the minimum price from an advert
*
* @param [type] $advert
* @return Price[]
*/
public function getAdvertMinPrice($advert): array
{
return $this->createQueryBuilder('p')
->andWhere('p.price = (
SELECT MIN(p2.price)
FROM ' . $this->_entityName . ' p2
WHERE p2.advert = :val
)'
)
->setParameter('val', $advert)
->getQuery()
->getResult()
;
}
}
有价格命名空间:
<?php

namespace App\Entity\advert;

use App\Entity\advert\Advert;
use App\Entity\advert\Period;
use App\Entity\backend\Season;
use App\Entity\backend\Duration;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

/**
* @ORM\Entity(repositoryClass="App\Repository\advert\PriceRepository")
*
* @UniqueEntity(
* fields={"duration", "season"},
* message="A price already exists for this season and this duration."
* )
*/
class Price
{
以及我遇到问题的文件中的 use 命令:
<?php

namespace App\Controller\advert;

use App\Entity\backend\VAT;
use App\Entity\advert\Price;
我不明白问题出在哪里。我已经搜索了几天没有结果。
有人会知道这个问题的起源吗?

最佳答案

简单地重新加载窗口(VSCode)通常可以解决问题。无需重新安装扩展程序。

要重新加载 vscode 打开命令面板( F1 )并选择 Developer: Reload Window .这相当于重新启动编辑器。

关于php - Visual Studio Code PHP Intelephense 收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59444350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com