vscode-intelephense icon indicating copy to clipboard operation
vscode-intelephense copied to clipboard

occasional false warning 'Cannot use 'parent' in a class with no parent.intelephense(1035)'

Open joachim-n opened this issue 3 years ago • 9 comments

Describe the bug

I sometimes see the warning 'Cannot use 'parent' in a class with no parent.intelephense(1035)' for a parent::foo() call on a class that has a parent.

To Reproduce

I'm not able to reproduce this; it's intermittent.

I've just tried opening the same file that's causing the problem in a different project window, and it's not showing the error there.

Just before getting the error, I'd applied a patch which hadn't applied completely, and the file in question had a failed hunk which was a class import statement, so it's possible that the parser got confused by this. But the missing import is now in place, so the parsing should be updated and the error removed.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Platform and version

MacOS.

joachim-n avatar Jul 08 '21 09:07 joachim-n

Im having the same issue with VSCode on Windows 10.

Issue occurs when my project's class extends a 3rd party class that isnt managed by composer.

Currently working on WordPress projects (where it doesn't make sense to use composer to manage dependencies), but im sure there are other use cases beyond WP.

To Reproduce

<?php

namespace MyNamspace;

use ThirdPartyClass;

class MyClass extends ThirdPartyClass {
  public function __construct(){
    parent:__construct();
    $this->some_other_code();
  }
  // rest of file.
}

Screenshots

image

justlevine avatar Jul 29 '21 21:07 justlevine

@justlevine is the 3rd party code in your open workspace folder or is it external and linked via intelephense.environment.includePaths?

bmewburn avatar Aug 01 '21 04:08 bmewburn

@bmewburn open in the workspace. However in past versions, even that wouldn't have mattered, the extends would have been enough for it to know that the class is a child... and therefore has a parent.

justlevine avatar Aug 01 '21 08:08 justlevine

I'm having the same issue with sublime text / debian / symfony 2.8 application. With a simple class extending HttpFoundation\Request

pacoVela avatar Jan 17 '22 17:01 pacoVela

I am also facing this issue with a class that extends from a composer package from vendor that is loaded via PSR-4 autoloading.

Neovim 0.6.1 macOS 12.1

codepuncher avatar Feb 03 '22 17:02 codepuncher

Same issue xampp with PHP v5.5.19 windows 11

Gildedter avatar Jul 05 '22 08:07 Gildedter

Hi all, I just encountered the error and it seems to be due to VSCode (I assume it's the intelephense extension specifically) automatically adding use parent; to the top of the file, when writing parent::__construct.

The duplicate definition of 'parent' then rightly throws an error.

So for anyone still facing this problem, check if there is a use parent; statement at the top of your file

tws-pockets avatar Jul 06 '22 04:07 tws-pockets

I still have this issues also on other IDEs like neovim...

Mte90 avatar Aug 05 '22 15:08 Mte90

immagine

An example of the error, maybe this helpful to fix @bmewburn? It is very annoying and there isn't a way to silence errors by settings.

Mte90 avatar Aug 29 '22 10:08 Mte90

noname-crop

https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/09e55701e1f7a616f990dcd63def7b873e615983/src/Console/Command/FixCommand.php

I'm having the same issue with VSCode 1.76

How to fix the error?

realodix avatar Mar 12 '23 08:03 realodix

Anyone get an update on if this issue is going to be addressed? Im still getting VS code yelling at me because there's no parent class even though Im extending a class.

tomascordero avatar Aug 07 '23 19:08 tomascordero