Page MenuHomePhabricator

Phan failed to catch undefined variable
Closed, ResolvedPublic

Description

In change 686626, LogEventsList.php was written as follows (reduced example):

public static function showLogExtract(
	&$out, $types = [], $page = '', $user = '', $param = []
) {

	$pager = new LogPager();
	$numRows = $pager->getNumRows();

	if ( $page instanceof PageReference ) {
		$pageName = 'db key here';
	} elseif ( $page != '' ) {
		  $pageName = $page;
	}

	if ( $numRows > $pager->mLimit ) {
		$urlParam = [];
		$urlParam['page'] = $pageName;
	}
}

This caused Undefined variable: $pageName, as reported and fixed in T282834.

This task is to understand why our automation tool )Phan) didn't catch this case of a conditionally-defined variable, used under no condition (or a different condition).

/cc @daniel @Pchelolo as authors/reviewers.

Event Timeline

The PhanPossiblyUndeclaredVariable issue is suppressed in core

Change 693646 had a related patch set uploaded (by DannyS712; author: DannyS712):

[mediawiki/core@master] Phan: enable PhanPossiblyUndeclaredVariable issue warnings

https://gerrit.wikimedia.org/r/693646

Krinkle renamed this task from Phan failed to catch undefined variable (retro for T282834) to Phan failed to catch undefined variable.Mar 26 2022, 7:22 PM
Krinkle edited projects, added Developer Productivity; removed Patch-For-Review.
Umherirrender subscribed.

The PhanPossiblyUndeclaredVariable issue is suppressed in core

T259172: Remove suppression of PhanPossiblyUndeclaredVariable issue in core.

The suppression is now gone. Needs retesting if the code would be catched or if this is a upstream issue.

Change 693646 abandoned by Umherirrender:

[mediawiki/core@master] Phan: enable PhanPossiblyUndeclaredVariable issue warnings

Reason:

Now superseeded by I1f200ac37df7448453688bf464a8250c97313e5d

https://gerrit.wikimedia.org/r/693646

Umherirrender claimed this task.

I have undo the change from https://gerrit.wikimedia.org/r/c/mediawiki/core/+/690784 locally and run phan

includes\logging\LogEventsList.php:711 PhanPossiblyUndeclaredVariable Variable $pageName is possibly undeclared
includes\logging\LogEventsList.php:765 PhanPossiblyUndeclaredVariable Variable $pageName is possibly undeclared

Now detected