Page MenuHomePhabricator

Remove use of PHP extract() function (use explicit assignment)
Closed, ResolvedPublic

Description

extract() makes variables appear from nowhere, and should really be cleaned up in most (all?) cases to be made explicit.

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:20 PM
bzimport set Reference to bz26496.
bzimport added a subscriber: Unknown Object (MLST).

Although $var->extract( calls were also matched, here's a resultspage that may be useful to see visualy:
http://toolserver.org/~krinkle/wikimedia-svn-search/view.php?id=59&hash=808b5bef729e4547355d3c659d16a0dd#F5

ViewVC links in the right column.

Heh... it's a shame PHP doesn't have destructuring assignment for non-numeiric arrays/objects.

Krinkle renamed this task from extract() sucks (change for explicit definition) to PHP extract() sucks (change for explicit definition).Dec 10 2014, 2:12 PM
Krinkle updated the task description. (Show Details)
Krinkle added a project: Technical-Debt.
Krinkle set Security to None.
Krinkle removed a subscriber: Unknown Object (MLST).

Change 271358 had a related patch set uploaded (by Ricordisamoa):
Replace extract() with explicit variable definitions in DjVuImage

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

Change 271358 merged by jenkins-bot:
Replace extract() with explicit variable definitions in DjVuImage

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

Heh... it's a shame PHP doesn't have destructuring assignment for non-numeiric arrays/objects.

https://wiki.php.net/rfc/list_keys has been implemented in PHP 7.1

So instead of

$arr = unpack( 'a4magic/a4chunk/NchunkLength', $header );
$chunk = $arr['chunk'];
$chunkLength = $arr['chunkLength'];

you should be able to write

[ 'chunk' => $chunk, 'chunkLength' => $chunkLength ] = unpack( 'a4magic/a4chunk/NchunkLength', $header );
Krinkle renamed this task from PHP extract() sucks (change for explicit definition) to Remove use of PHP extract() function (use explicit assignment).Dec 27 2017, 9:16 PM
Krinkle moved this task from Unsorted to Needs refactor on the Technical-Debt board.

Change 413937 had a related patch set uploaded (by MaxSem; owner: MaxSem):
[mediawiki/core@master] Don't suggest using extract()

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

Change 413937 merged by jenkins-bot:
[mediawiki/core@master] Don't suggest using extract()

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

Mainframe98 added a subscriber: Mainframe98.

The few calls are either for tests or $GLOBALS (and mostly a combination of both) or false positives of methods called extract. MediaWiki-Codesniffer bans usage of extract anyways. (T180398)

Yeah, well done all for the fixes in the past three years. :-)