Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未定义的方法';按学生获取课程&x27;_Php_Visual Studio Code_Doctrine - Fatal编程技术网

Php 未定义的方法';按学生获取课程&x27;

Php 未定义的方法';按学生获取课程&x27;,php,visual-studio-code,doctrine,Php,Visual Studio Code,Doctrine,我正在做一个项目,使用PHP和条令只是为了学习的目的,我得到了一个错误,我不知道是什么原因造成的。 我创建了一个名为Student.php的类,它有一个自定义存储库类,可以对我的数据库进行自定义获取。问题是,在代码执行期间,我没有收到任何错误,代码一切正常,它运行正常,工作正常,但是IDE说我的自定义获取方法没有定义,即使它工作正常。 我正在使用VS代码 以下是我的自定义方法的作用: <?php namespace Alura\Doctrine\Repository; use Alu

我正在做一个项目,使用PHP和条令只是为了学习的目的,我得到了一个错误,我不知道是什么原因造成的。
我创建了一个名为Student.php的类,它有一个自定义存储库类,可以对我的数据库进行自定义获取。问题是,在代码执行期间,我没有收到任何错误,代码一切正常,它运行正常,工作正常,但是IDE说我的自定义获取方法没有定义,即使它工作正常。
我正在使用VS代码

以下是我的自定义方法的作用:

<?php

namespace Alura\Doctrine\Repository;

use Alura\Doctrine\Entity\Student;
use Doctrine\ORM\EntityRepository;

class StudentRepository extends EntityRepository
{
    public function fetchCoursesByStudent()
    {
        $entityManager = $this->getEntityManager();
        $studentClass = Student::class;
        $dql = "SELECT s, p, c FROM $studentClass s JOIN s.phones p JOIN s.courses c";
        $query = $entityManager->createQuery($dql);
        return $query->getResult();
    }
}


您的IDE不知道$studentsRepository是什么类型的,所以它无法告诉您哪些方法可能有或可能没有。@CBroe通过阅读您的评论,我想在
$studentsRepository
上方添加一行docblock
/**@var EntityRepository$studentsRepository*/
来解决问题。也许你可以把这个评论作为一个答案,这样我就可以给你帮助我的功劳。