phpdoc-parser icon indicating copy to clipboard operation
phpdoc-parser copied to clipboard

Fix global variables wrongly parsed

Open Lucisu opened this issue 3 years ago • 1 comments

Fixes issue #230 by checking if the variable is global before assigning it to the $this->last_doc.

Lucisu avatar Oct 04 '22 00:10 Lucisu

We also need to reset the last doc to null, when we declare a function/method, as otherwise it will apply the tags in cases like:

/**
 * @deprecated some text 
 */
add_filter( 'foo', 'bar' );

/**
 * @deprecated other text
 */
function hello() {
	return apply_filters( 'my_filter', '' );
}

"my_filter" will suddenly have the @deprecated some text comment added, even though it's completely irrelevant

Just add $this->last_doc = null; before this line https://github.com/WordPress/phpdoc-parser/blob/6540706a2a08648aad1e8a0d5ba0bc50c3ea4f45/lib/class-file-reflector.php#L74

kkmuffme avatar Apr 03 '23 08:04 kkmuffme