-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix NoEmptyIfDefined behaviour with dynamic properties
Use hasDynamicProperties(), which already checks for stdClass, and also for the AllowDynamicProperties attribute as of phan 5.4.2. Also mention the addition of the NoBaseException plugin in the release notes. Bug: T349432 Change-Id: I61acc0f6924e14b76fb6a2199dd67d5041c4e650
- Loading branch information
Showing
4 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
// @phan-file-suppress PhanUndeclaredProperty,PhanNoopEmpty | ||
// @phan-file-suppress PhanUndeclaredClassAttribute,UnusedPluginSuppression,UnusedPluginFileSuppression | ||
// Different suppressions are needed in different PHP versions (7.4 does not "see" the attribute at all, 8.0 and 8.1 | ||
// see it but can't find the class, 8.2 sees it and knows what it is). | ||
|
||
class ClassForDynamicPropWithoutAttribute { | ||
} | ||
|
||
#[AllowDynamicProperties] | ||
class ClassForDynamicPropWithAttribute { | ||
} | ||
|
||
function testWithoutAttrib( ClassForDynamicPropWithoutAttribute $param ) { | ||
$withoutAttrib = new ClassForDynamicPropWithoutAttribute(); | ||
empty( $withoutAttrib->dynamicProp ); | ||
$withoutAttrib->dynamicProp2 = 'Hello'; | ||
empty( $withoutAttrib->dynamicProp2 ); | ||
|
||
empty( $param->dynamicProp ); | ||
empty( $param->dynamicProp2 ); | ||
empty( $param->dynamicProp3 ); | ||
} | ||
|
||
function testWithAttrib( ClassForDynamicPropWithAttribute $param ) { | ||
$withAttrib = new ClassForDynamicPropWithAttribute(); | ||
empty( $withAttrib->dynamicProp ); | ||
$withAttrib->dynamicProp2 = 'Hello'; | ||
empty( $withAttrib->dynamicProp2 ); | ||
|
||
empty( $param->dynamicProp ); | ||
empty( $param->dynamicProp2 ); | ||
empty( $param->dynamicProp3 ); | ||
} | ||
|
||
#[AllowDynamicProperties] | ||
class TestAttributeInheritanceBase {} | ||
|
||
class TestAttributeInheritanceChild extends TestAttributeInheritanceBase {} | ||
|
||
class ExtendsStdClass extends stdClass {} | ||
|
||
function testInheritance() { | ||
$base = new TestAttributeInheritanceBase(); | ||
empty( $base->x ); | ||
|
||
$child = new TestAttributeInheritanceChild(); | ||
empty( $child->y ); | ||
|
||
$extendsStdClass = new ExtendsStdClass(); | ||
empty( $extendsStdClass->z ); | ||
} |