phptools-docs
phptools-docs copied to clipboard
Renaming private property should not automatically rename property with same name in extending/parent class
I'm using VSCode witht the latest pre-release of the extension.
<?php
declare(strict_types=1);
namespace MyNamespace;
class MyClass extends Dad
{
private int $myProp;
}
class Dad
{
private int $myProp;
}
If you use the rename refactor tool to rename a private property, it should not automatically rename a private property of the same name in an extending class, since they are completely different properties. Someone may still want to rename it in all those places, but it should be considered a risky rename that brings up the list of possible renames and these would remain unchecked by default. It should be changed to work this way regardless of which class you try to rename it from, either the parent or the extending class.
It should also work the same way if the property is private in the parent, but is not private in the extending class, since they would still be separate properties.
This bug still exists, it is not related to any other issues I reported.
Thank you for reminding me.
Implemented in the latest release; but only if you're renaming the declaration of the property itself (i.e. private var $property;).
If renaming a property use (i.e. $this->property), we may still treat it as public, and hence rename all occurences - working on this one.
I just tried something related to this in the most recent non-prerelease version v1.42.14626. I'm actually testing a simpler case where I'm just renaming a private property in a final class, there are no extending/parent classes to worry about. I tried renaming it at the property declaration, and I get this error:
[Error - 7:10:25 PM] Request textDocument/rename failed.
Message: Cannot rename element of type FieldDecl as Field, IsPrivate.
Code: 101
If I rename it at a usage, it works.
I switched to the pre-release v1.42.14717 and I am able to rename it from either the property declaration or a use, at least for this simpler scenario.
@still-dreaming-1 thank you for testing it. Right, 1.42.14717 is the latest pre-release. The previous one has that bug.
@still-dreaming-1 finally we've fixed the private fields semantic highlighting and rename refactoring!
Thanks for reporting that. The fix will be in the next update.