클래스에 대한 여러 정의가 있습니다.
여러 클래스 정의 (응용 프로그램 및 시스템 하위 폴더)를 허용하는 Kohana 프레임 워크를 사용하고 있습니다. 나에게 메시지를 제공하는 IDE로 phpstorm을 사용하고 있습니다 multiple definitions exist for class
. phpStorm에게 어떤 클래스 정의가 올바른지 알려주는 방법이 있습니까?
PhpStorm에게 어떤 클래스 정의가 올바른지 알려주는 방법이 있습니까?
불행히도 할 수 없습니다.
https://youtrack.jetbrains.com/issue/WI-17646- 진행 상황에 대한 알림을 받으려면이 티켓 (별표 / 투표 / 댓글)을 시청 하세요 .
ATM은 흔들리지 않는 ..을 무시하거나 그러한 사례를보고하지 않도록 검사를 구성 할 수 있습니다 ( Settings/Preferences | Editor | Inspections | Undefined | Undefined class | Don't report multiple class declaration potential problems
).
검사가 구성되어 있어도 IDE는 점프 할 클래스 선언을 묻습니다 (이는 IDE가 원래 구현을 보거나 직접 구현할지 여부를 알지 못하므로 올바른 동작입니다).
다른 방법은 프로젝트에 동일한 이름의 클래스가 하나만 있는지 확인하는 것입니다.
- 전체 폴더를 제외됨으로 표시
- 개별 파일을 일반 텍스트로 표시
둘 다 프로젝트보기의 콘텐츠 메뉴를 통해 사용할 수 있으며 프로젝트 파일에만 적용 할 수 있습니다 (예 : 라이브러리 범위에 적용하려고하면 사용할 수 없거나 유용하지 않음).
전체 캐시 폴더는 무시해야합니다.
- 설정> 디렉토리로 이동합니다.
- 고르다
var\cache
- '제외'로 설정
출처 : https://github.com/Haehnchen/idea-php-symfony2-plugin/issues/301
내 문제에 대한 가능한 해결책을 찾았습니다. mark file as plain
변형으로 특정 클래스에 대해서만 검사를 끌 수 있습니다. 저조한 클래스 이름 안에 커서를 놓고 Alt+Enter
→ Inspection options
→Supress for statement
PHPStorm 추가
/** @noinspection PhpUndefinedClassInspection */
위의 클래스 선언과 클래스 이름은 더 이상 흔들리지 않습니다.
나는 모든 곳에서 웹을 둘러 보았고 하나의 옵션이 저에게 효과가 없었습니다 ... 몇 달 동안 어려움을 겪어 왔으며 오늘 해결책을 찾았으므로 위의 방법 중 어느 것도 효과가 없다면 PHP를 재정의하십시오. 경로 목록 포함. 설정> 언어 및 프레임 워크> PHP에서 프로젝트 또는 애플리케이션에서 사용하는 소스 경로가 포함 된 폴더 만 구성되어 있는지 확인합니다.
내 시나리오는 내가 많은 패키지 개발을 수행하고 내 패키지가 모두 하나의 프로젝트에있는 동안 내 컴포저 구성의 "공급 업체"에서도 "symlinked"이므로 공급 업체 폴더에 PHPStorm에서 찾은 중복 코드가 있습니다. 내 패키지 폴더. 마찬가지로 포함 경로가 중복되거나 이미 프로젝트의 일부인 프로젝트 외부의 코드를 찾도록 경로가 구성된 경우 여러 정의도 찾습니다. 따라서 공급 업체에서 심볼릭 링크 된 폴더를 제외하면 PHPStorm이 내 패키지에 대한 소스 복사본을 하나만 찾을 수 있으며 내 패키지에 자체 공급 업체 폴더가 포함되어 있으면 중복 된 정의로 표시됩니다. 포함 경로 목록에서 중복을 찾을 수있는 항목을 제거합니다.
프로젝트 어딘가에 동일한 클래스에 대한 여러 정의가 있습니다. 이 경고를 일으킨 프로젝트에 백업 복사본이 있음을 발견했습니다. 내 프로젝트에서 백업을 제거하고 (어쨌든 좋은 생각) 오류를 수정했습니다.
다른 정의를 어떻게 만들 었는지 모르겠지만을 (를) 호출하여이 문제가 발생한 class_alias()
경우이 문제를 빠르게 해결할 수 있습니다.
중히 여기다
class_alias(
'The\AliasClass',
'My\RealClass',
true
);
과
class_alias(
'The\AliasClass',
'My\Real'.'Class', // <-- break up the string
true
);
후자를 사용하면 PhpStorm이이를 선택하지 않고 My\RealClass
"다중 정의"경고가 중지됩니다. 그건 그렇고, 이것은 문자열 리터럴에 HTML을 포함하는 고대 JavaScript 트릭입니다.
이 경고는 오랫동안 나를 괴롭 혔습니다. 어딘가에 중복 파일이 있다는 답변이 정확하다고 생각합니다. 내가 경고를받는 이유는 phpStorm에게 codeIgniter 함수를 찾는 방법에 대한 힌트를 제공하는 자동 완성 파일 때문입니다. 이 작업을 수행하는 경우에도 일부 경고가 발생합니다. 자동 완성 파일은 phpStorm이 두 가지 다른 정의가 있다고 생각하게합니다. 그러나 나는 경고를 싫어하는 것보다 자동 완성을 더 좋아하기 때문에 나는 그들과 함께 살아야 할 것 같다.
이것이 제가 언급하는 자동 완성입니다 : IntelliJ IDEA 12가 CodeIgniter 클래스를 찾지 못해 오류가 발생합니다.
유행을 따라 작동하지만 그다지 좋지 않은 대안
- 자동 완성에서 사용하지 않을 파일 B를 "일반"으로 표시하거나 제외하고 파일 A를 활성 상태로 둡니다. 이렇게하면 파일 C에서 알림이 비활성화 되지만 파일 B에있는 모든 항목에 대해 더 이상 자동 완성이 작동하지 않습니다 . 따라서 다른 곳에서 B에있는 것을 올바르게 사용하고 A를 자동 완성에서 제외하려는 경우 그렇게 할 수 없습니다.
- 검사 비활성화 : 정의되지 않은 클래스 경고도 비활성화되므로 클래스 이름에 오타를 입력하면 배포 후 (또는 자동 완성이 해당 객체에 대해 작동을 중지한다는 사실에서)이를 발견 할 수 있습니다.
- "여러 클래스 선언의 잠재적 인 문제를보고하지 마십시오"-이것은 거의 훌륭하지만 "잠재적 인 문제"를 무시하는 것을 좋아하지 않습니다. 다른 곳에서 사용중인 무의식적으로 중복 된 이름으로 클래스를 생성하면 어떻게됩니까? 내가 그것을 잡을 것이라고 (또는 phpunit이 할 것입니다),하지만 여전히 .
내가 지금까지 찾은 것 중 최고
적어도 PHPStorm에 대해보다 집중된 구성 (예 : "대체 클래스")을 사용할 수있을 때까지 지금 진행하는 방법은 해당 알림을 무시할 수 있도록 표시하는 것입니다.
/* @noinspection PhpUndefinedClassInspection */
/**
* Verify an existing contract. Requires agent and supervisor.
*
* @param array $data
* @param Cliente $cli
* @param User $age
* @param User $sup
* @return Contratto
*/
private function contratto(
array $data,
/* @noinspection PhpUndefinedClassInspection */
Cliente $cli,
/* @noinspection PhpUndefinedClassInspection */
User $age,
/* @noinspection PhpUndefinedClassInspection */
User $sup
) {
PHPDoc 주석에서 알림을 비활성화하려면 주석 앞에 지시문을 추가해야했습니다. 이것은 세 매개 변수에 대한 알림을 비활성화하지 않았습니다 .
앞으로 PHPStorm에서 다음과 같이 지정할 수 있기를 바랍니다.
* @param array $data raw data for the contract
* @param \local\foobar\Cliente $cli customer opening the contract
private function contratto(
array $data,
/*\local\foobar\*/Cliente $cli,
or better still, explicitly use a new PHPdoc tag such as "@replaces". So PHPStorm would know that my class is the one not replaced. I'll also have to decorate my use
's to specify the class I'll be actually using.
And run a search for "@noinspection PhpUndefinedClassInspection" throughout my code.
Another way
The above problems stem from the fact that I have a "master" Customer class which is overridden by a "local" modification for the foobar client, whose Customers have (say) a special method.
The "correct" way of doing this should be to declare a FoobarCustomer which is only employed by foobar's code, and is a child class of Customer. Of course this is only possible if the child class is in my code, not in the framework's, and also I may need some methods in the parent class to be protected
rather than private
, which may make this solution either impossible or needful of Reflection:
/**
* Verify an existing contract. Requires agent and supervisor.
*
* @param array $data
* @param FoobarCliente $cli
* @param FoobarUser $age
* @param FoobarUser $sup
* @return Contratto
*/
private function contratto(array $data, FoobarCliente $cli, FoobarUser $age...
I had similar problem and it was quite annoying one. I was using Yii2 framework and as it turned out at the end I have accidentally created en extra "vendor" folder and composer.json in the root of the project (not in the root of the app) so I ended up with that warning as phpStorm was confused which extension folder is the right one. I've deleted extra vendor folder and it solved the problem.
Prolog
Guess there are several ways to solve this problem. Actually its just a warning and it says that phpstorm can't provide you with autocompletion so you have to work a bit harder :D
I had the same problem as many others here and solved it by ignoring unwanted.
Szenario
Had a git project with a vendor-folder after composer install. Also there is a my-project.phar
in this project that also contains some vendor stuff and this caused my warnings.
Solution
File > Preferences|Settings > Directories
There you have to possibility to exclude files and folders. In my case it's the .phar
so it's a "file" and you can add it in the bottom of the settings-window.
PHPStorm will no longer see duplicates.
This is very project specific and i guess moste people have to find they're own solution but pointing to this my help to find the problem easier.
Hope this helps someone :)
I resolved this in my case by removing a more specific entry in my composer.json that included code by another more general entry
참고URL : https://stackoverflow.com/questions/23066665/multiple-definitions-exist-for-class
'program story' 카테고리의 다른 글
비트 맵에 굵은 텍스트를 어떻게 그리나요? (0) | 2020.12.14 |
---|---|
각 열에 varchar (MAX)를 사용했지만 CSV 파일을 가져 오는 동안 SQL Server의 오류 (0) | 2020.12.14 |
Visual Studio Code-VS Code에 여전히 표시되는 GitHub에서 삭제 된 분기를 제거 하시겠습니까? (0) | 2020.12.14 |
Explict Annotation Processor 설정 (0) | 2020.12.14 |
PDF 출력이있는 PHP PDF 템플릿 라이브러리? (0) | 2020.12.13 |