vscode-intelephense
vscode-intelephense copied to clipboard
occasional false warning 'Cannot use 'parent' in a class with no parent.intelephense(1035)'
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.
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
@justlevine is the 3rd party code in your open workspace folder or is it external and linked via intelephense.environment.includePaths
?
@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.
I'm having the same issue with sublime text / debian / symfony 2.8 application. With a simple class extending HttpFoundation\Request
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
Same issue xampp with PHP v5.5.19 windows 11
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
I still have this issues also on other IDEs like neovim...
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.
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?
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.