Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File::getMemberProperties() is recognizing method params as properties #2214

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,18 @@ public function getMemberProperties($stackPtr)
}
}

// Make sure it's not a method parameter.
if (empty($this->tokens[$stackPtr]['nested_parenthesis']) === false) {
$parenthesis = array_keys($this->tokens[$stackPtr]['nested_parenthesis']);
$deepestOpen = array_pop($parenthesis);
if ($deepestOpen > $ptr
&& isset($this->tokens[$deepestOpen]['parenthesis_owner']) === true
&& $this->tokens[$this->tokens[$deepestOpen]['parenthesis_owner']]['code'] === T_FUNCTION
) {
throw new TokenizerException('$stackPtr is not a class member var');
}
}

$valid = [
T_PUBLIC => T_PUBLIC,
T_PRIVATE => T_PRIVATE,
Expand Down
18 changes: 18 additions & 0 deletions tests/Core/File/GetMemberPropertiesTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,21 @@ $globalVariable = true;

/* testNotAVariable */
return;

$a = ( $foo == $bar ? new stdClass() :
new class() {
/* testNestedProperty 1 */
public $var = true;

/* testNestedMethodParam 1 */
public function something($var = false) {}
}
);

function_call( 'param', new class {
/* testNestedProperty 2 */
public $year = 2017;

/* testNestedMethodParam 2 */
public function __construct( $open, $post_id ) {}
}, 10, 2 );
19 changes: 19 additions & 0 deletions tests/Core/File/GetMemberPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,22 @@ public function dataGetMemberProperties()
'/* testInterfaceProperty */',
[],
],
[
'/* testNestedProperty 1 */',
[
'scope' => 'public',
'scope_specified' => true,
'is_static' => false,
],
],
[
'/* testNestedProperty 2 */',
[
'scope' => 'public',
'scope_specified' => true,
'is_static' => false,
],
],
];

}//end dataGetMemberProperties()
Expand Down Expand Up @@ -346,9 +362,12 @@ public function testNotClassPropertyException($identifier)
public function dataNotClassProperty()
{
return [
['/* testMethodParam */'],
['/* testImportedGlobal */'],
['/* testLocalVariable */'],
['/* testGlobalVariable */'],
['/* testNestedMethodParam 1 */'],
['/* testNestedMethodParam 2 */'],
];

}//end dataNotClassProperty()
Expand Down